我正在尝试用java缩放byte[]
形式的图像但当我设置缩放参数并获得异常时,我的缩放变量返回null
public static byte[] resizeImage(byte[] image) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(image);
Image tmpImage = ImageIO.read(bais);
ImageIcon imageIcon = new ImageIcon(tmpImage);
Image scaled = imageIcon.getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH);
BufferedImage buffered = ((ToolkitImage) scaled).getBufferedImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(buffered, "jpeg", baos);
baos.flush();
image = baos.toByteArray();
baos.close();
return image;
}
使用BufferedImage buffered = ImageIO.read(new ByteArrayInputStream(byte));
创建BufferedImage
,然后检查如何在java中调整Image的大小?了解如何调整大小。