Make a BufferedImage use less RAM?

后端 未结 6 1353
挽巷
挽巷 2020-12-25 08:02

I have java program that reads a jpegfile from the harddrive and uses it as the background image for various other things. The image itself is stored in a BufferImage

6条回答
  •  忘掉有多难
    2020-12-25 09:01

    You could copy the pixels of the image to another buffer and see if that occupies less memory then the BufferedImage object. Probably something like this:

    BufferedImage background = new BufferedImage(
       width, 
       height, 
       BufferedImage.TYPE_INT_RGB
    );
    
    int[] pixels = background.getRaster().getPixels(
        0, 
        0, 
        imageBuffer.getWidth(), 
        imageBuffer.getHeight(), 
        (int[]) null
    );
    

提交回复
热议问题