图形学 - Java修改图片尺寸,总是报内存溢出怎么解决?
大家讲道理
大家讲道理 2017-04-18 10:04:01
0
5
719
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(5)
黄舟

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

刘奇

You can try it ImageMagick

伊谢尔伦

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"));
伊谢尔伦
    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));  
迷茫

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template