Graphics2D: Drawing black on white?

前端 未结 1 1786
一整个雨季
一整个雨季 2021-02-18 23:21

I\'m sure this is a very stupid question but I can\'t find the answer, I\'m not experienced with the Java2D API. I\'m trying to create an image and write it to GIF or PNG, and I

1条回答
  •  抹茶落季
    2021-02-18 23:32

    The setBackground method is/was only for use with the clearRect method.

    Fill the rectangle with the background colour before painting:

    int width = 200;
    int height = 400;
    BufferedImage image = new BufferedImage(width, height,
                              BufferedImage.TYPE_BYTE_BINARY);
    Graphics g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, width, height);
    g.setColor(Color.BLACK);
    //ready for drawing
    

    0 讨论(0)
提交回复
热议问题