Now I am using this code to read an icon image from disk:
String fullImagePath = imageDiskPath + localIconUrl;
String extensionName = FilenameUtils.getExtension(localIconUrl);
BufferedImage img;
if("ico".equals(extensionName)){
img = Imaging.getAllBufferedImages(new File(fullImagePath)).get(0);
}else{
img = ImageIO.read(new File(fullImagePath));
}
if(img == null){
log.error("read image return home,url:" + fullImagePath);
return null;
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(img, extensionName, os);
byte[] array = os.toByteArray();
if(ArrayUtils.isEmpty(array)){
log.error("array is null");
return null;
}
but when I read an icon image,the result ByteArrayOutputStream
is null. This is the debug output:
Am I doing wrong? what should I do to make it read an icon and convert to bas64 successfully? I am using this package to read the icon:
api group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-alpha2'
I have also tried this way:
img = Imaging.getBufferedImage(new File(fullImagePath));
still not work.