我有一个以字节数组形式存储的图像。无论大小如何,我都希望将其调整为100x100像素。
我正在尝试将字节数组转换为缓冲图像,调整大小并将其保存回字节数组。但是使用以下代码后,图像不再出现在我的页面上。
byte[] pict; // this array contains the image
BufferedImage bufferedImage;
ByteArrayInputStream bais = new ByteArrayInputStream(pict);
try {
bufferedImage = ImageIO.read(bais);
bufferedImage = Scalr.resize(bufferedImage, 100);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bufferedImage, "jpg", baos );
baos.flush();
pict = baos.toByteArray();
baos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
OutputStream o = response.getOutputStream();
o.write(pict);