如何将本地图片转换为byte[]数组呢,下面是今天找到的解决办法。
public static byte[] getImageData(File file,String format){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
BufferedImage bImage =ImageIO.read(new FileInputStream(file));
ImageIO.write(bImage, format, out);
} catch (IOException e) {
e.printStackTrace();
}
return out.toByteArray();
}
public static BufferedImage getImage(byte[] buff){
ByteArrayInputStream bais=new ByteArrayInputStream(buff);
BufferedImage image=null;
try {
image=ImageIO.read(bais);
} catch (IOException e) {
e.printStackTrace();
}
return image;
}