OiO.lk Blog java BufferedImage.Type_INT_RGB and BufferedImage.TYPE_INT_ARGB drawing differently?
java

BufferedImage.Type_INT_RGB and BufferedImage.TYPE_INT_ARGB drawing differently?


I noticed that when trying to draw a square with a black border for BufferedImage graphics it works fine if it is instantiated as TYPE_INT_RGB but it deforms if the BufferedImage was made as TYPE_INT_ARGB seemingly only putting the border on the left and top of the square.

icon = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = icon.createGraphics();
        g.setColor(Color.yellow);
        g.fillRect(0, 0, (int) this.width-1, (int) this.height-1);
        g.setColor(Color.BLACK);
        g.drawRect(0, 0, (int) this.width, (int) this.height);
        g.dispose();

If you try it and get rid of the A in TYPE_INT_ARGB you see what I mean. It is no problem with the squares but it becomes one when I draw circles. In fact, it looks like it is drawing the contents further down and to the left then it does as TYPE_INT_RGB.



You need to sign in to view this answers

Exit mobile version