ByteArrayOutputStream未正确设置

时间:2013-07-26 12:55:59

标签: java bufferedimage bytearrayinputstream

MultipartFile mpf = null;
final BufferedImage resizedImage = imageResizeService.resize(requestResizeReq);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ImageIO.write( resizedImage,mpf.getContentType() , baos );
         profilePictureService.saveProfilePicture(account.getId(),baos.toByteArray());

resizedImage

BufferedImage@1f79b067: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@65da4a76 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 200 height = 500 #numDataElements 3 dataOff[0] = 701

baos为空。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

找出内容类型的问题。它是image / jpeg所以新代码如下所示。

 ImageIO.write( resizedImage,mpf.getContentType().replace("image/", "") , baos );