黄舟2017-04-18 10:06:01
GraphicsMagick+im4java can handle it. GraphicsMagick does not need to read the entire image into the memory. It is much more efficient than using the native one. You can search and see. In the past, we used GraphicsMagick to process image cropping
伊谢尔伦2017-04-18 10:06:01
You can try it, I’m not sure if it will work either
int w = 400;
int h = 300;
BufferedImage oldImg = ImageIO.read(new File("F:\sample.jpg"));
Image t = oldImg.getScaledInstance(w, h, Image.SCALE_FAST);
BufferedImage newImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = newImg.createGraphics();
g.drawImage(t, 0, 0, w, h, null);
g.dispose();
ImageIO.write(newImg, "jpg", new File("F:\small.jpg"));
伊谢尔伦2017-04-18 10:06:01
File srcFile = new File(srcImgPath);
Image srcImg = ImageIO.read(srcFile);
BufferedImage buffImg = null;
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
buffImg.getGraphics().drawImage(
srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
0, null);
ImageIO.write(buffImg, "JPEG", new File(distImgPath));
迷茫2017-04-18 10:06:01
The idea can be changed. Obviously the compressed image can be stored in the memory, and large images should be partially read and processed before being put into the compressed graphics. In general, this problem is not difficult, just change the idea.