2013-07-26 76 views
0
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()); 

resizedImageByteArrayOutputStream設置不正確

[email protected]: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = [email protected] transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 200 height = 500 #numDataElements 3 dataOff[0] = 701 

baos是空的。任何想法?

+0

想要得到更快的幫助,請發佈[SSCCE](http://sscce.org/)。熱鏈接到具有相同結果的小圖像(以字節爲單位)。 –

回答

0

發現內容類型的問題。它是image/jpeg,所以新代碼如下所示。

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

ImageIO.write(...)的Javadoc說:

寫入使用支持 給定格式的一個OutputStream任意ImageWriter的圖像。

返回false,如果沒有適當的作家中找到。

所以檢查返回值boolean ImageIO.write(...)。我想沒有找到合適的作家。