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());

resizedImage is

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 is empty. Any idea?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212

1 Answers1

0

Found out the problem with content type. It was image/jpeg so the new code looks like follows.

 ImageIO.write( resizedImage,mpf.getContentType().replace("image/", "") , baos );
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212