Converting a 32bpp image to a 16bpp image in Java

后端 未结 2 402
醉话见心
醉话见心 2021-01-23 06:30

How could a 32bpp image ( ARGB ) could be converted to a 16bpp image ( ARGB ) using Java\'s libraries? For my curiosity, at pixel level, what does this conversion do? If I have

2条回答
  •  星月不相逢
    2021-01-23 07:20

    Read in the image and save it in the format you need. From http://www.exampledepot.com/egs/javax.imageio/Graphic2File.html

    // Create an image to save
    RenderedImage rendImage = myCreateImage();
    
    // Write generated image to a file
    try {
        // Save as PNG
        File file = new File("newimage.png");
        ImageIO.write(rendImage, "png", file);
    
        // Save as JPEG
        file = new File("newimage.jpg");
        ImageIO.write(rendImage, "jpg", file);
    } catch (IOException e) {
    }
    

    See the output from javax.imageio.ImageIO.getWriterFormatNames() to locate the format you need.

    The internal representation of each pixel does not change (except for loss of representation) when using 16 bpp, but the bytes stored on disk will.

提交回复
热议问题