When i rescale height and width image it on rotate 90 degrees
@RequestMapping(value = "/save" , method = RequestMethod.POST, headers = "Content-Type=multipart/form-data", consumes = { "multipart/form-data" })
ResponseEntity<Object> saveBackground(@RequestParam(required = false) MultipartFile imageLeft){
BackgroundDto backgroundDto = new BackgroundDto();
backgroundDto.setLeftPage(imageLeft.getBytes()); --> saved right
//saved wrong orientation
backgroundDto.setMinLeftPage( CompressImages.compress(imageLeft.getBytes()));
backgroundDto.setUser(user);
backgroundRepo.save(backgroundDto);
}
public static byte[] compress(byte[] img) throws IOException {
InputStream inputstream = new ByteArrayInputStream(img);
ByteArrayOutputStream baosImage = new ByteArrayOutputStream();
ByteArrayOutputStream rescale = rescale(image);
return rescale.toByteArray();
}
private static ByteArrayOutputStream rescale(BufferedImage bi) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int originalWidth = bi.getWidth();
int originalHeight = bi.getHeight();
int type = bi.getType() == 0? BufferedImage.TYPE_INT_ARGB : bi.getType();
//rescale 50%
BufferedImage resizedImage = new BufferedImage(originalWidth/4, originalHeight/4, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(bi, 0, 0, originalWidth/4, originalHeight/4, null);
g.dispose();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ImageIO.write(resizedImage, "jpg",baos);
return baos;
}
backgroundDto.setLeftPage(imageLeft.getBytes()); --> saved right orientation backgroundDto.setMinLeftPage( CompressImages.compress(imageLeft.getBytes())); --> saved wrong orientation
Original image: enter image description here
image after rectange: enter image description here