3
我将图像存储为字节数组。无论尺寸有多大,我都希望将其缩小至100x100像素。以像素为单位调整字节数组图像的大小
我想将字节数组转换为bufferedimage,调整大小并将其保存为bytearray。但通过以下代码,图片不再出现在我的页面上。
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);
如果我这样做,我该如何将它改回字节数组。 – JasSy
更新为能够更改为bytearray。 –
试着用你的代码。图像仍然没有出现。 – JasSy