Create a BufferedImage from file and make it TYPE_INT_ARGB

后端 未结 3 715
醉酒成梦
醉酒成梦 2020-12-08 02:28

I have a PNG file with transparency that is loaded and stored in a BufferedImage. I need this BufferedImage to be of TYPE_INT_ARGB. Ho

3条回答
  •  一向
    一向 (楼主)
    2020-12-08 03:07

    try {
        File img = new File("somefile.png");
        BufferedImage image = ImageIO.read(img ); 
        System.out.println(image);
    } catch (IOException e) { 
        e.printStackTrace(); 
    }
    

    Example output for my image file:

    BufferedImage@5d391d: type = 5 ColorModel: #pixelBits = 24 
    numComponents = 3 color 
    space = java.awt.color.ICC_ColorSpace@50a649 
    transparency = 1 
    has alpha = false 
    isAlphaPre = false 
    ByteInterleavedRaster: 
    width = 800 
    height = 600 
    #numDataElements 3 
    dataOff[0] = 2
    

    You can run System.out.println(object); on just about any object and get some information about it.

提交回复
热议问题