java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt

前端 未结 3 924
忘了有多久
忘了有多久 2020-12-18 05:03

I have some errors atm while im coding with JAVA, I have been trying to fix this for along time, also trying to find oterh ppl who have same problem and fixed it but nothing

3条回答
  •  旧时难觅i
    2020-12-18 05:41

    To solve your problem, you need to change the BufferedImage type of

    private BufferedImage image = new BufferedImage(WIDTH, HEIGHT,  
    BufferedImage.TYPE_3BYTE_BGR);
    

    and change it to

    private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    

    the problem is that BufferedImage.TYPE_3BYTE_BGR uses byte[3] to represent each pixel and BufferedImage.TYPE_INT_RGB just uses an int

提交回复
热议问题