-1

I have BufferedImage that stores .png image (320 x 240) and I draw it on Сanvas with Graphics.drawImage(). But if you look closely, for example, the cross 3 by 3 pixels is actually 4 by 3 pixels. Look my question in the picture: enter image description here

GameContainer render method:

public void render() {
    bs = window.canvas.getBufferStrategy();
    if (bs == null) {
        window.canvas.createBufferStrategy(3);
        return;
    }
    g = (Graphics2D) bs.getDrawGraphics();
    gm.render(g);
    g.dispose();
    bs.show();
}



GameManager render method:

public void render(Graphics2D g) {
    b.render(g);
}



Background render method:

public void render(Graphics2D g) {
    g.drawImage(image, 0, 0 , null);
}
Archer
  • 67
  • 11
  • I think code is useless here. I just use Graphics.drawImage(image, x, y, 0); – Archer Jun 25 '20 at 18:59
  • I had similar issues in the past (many years ago ;-)) could relate to `RenderingHints`, have a look here maybe it helps https://stackoverflow.com/a/36316937/150623 & here https://docs.oracle.com/javase/tutorial/2d/advanced/quality.html – Tommy Brettschneider Jun 25 '20 at 19:00
  • Thanks Tommy. I also thought that problem in RenderingHints, but it didn't help me. – Archer Jun 25 '20 at 19:03
  • I noticed one thing. I changed the resolution of my window on (320 * 3) x (240 * 3) and used Graphics.scale(3, 3) (that scale my all graphics that I drew). Now I got image that looks like image that I drew, but I don't think that it is decision of my problem. – Archer Jun 25 '20 at 19:20

1 Answers1

-1

You may probably be using one of the overloads of drawImage() that scales the image to fit inside a particular area. You may take a look here: https://docs.oracle.com/javase/tutorial/2d/images/drawimage.html The following paragraph: For example, the following overload of the drawImage() method enables you to draw as much of a specified area of the specified image as is currently available, scaling it to fit inside the specified area of the destination drawable surface:

boolean Graphics.drawImage(Image img, int dstx1, int dsty1, int dstx2, int dsty2, int srcx1, int srcy1, int srcx2, int srcy2, ImageObserver observer);

  • Of course that would be ideal, but I just wanted to give some help, maybe the person that submitted the question is under a deadline pressure, or who knows what prevented him writing the actual code. Anyway, tried to help. – laurentiurad Jun 25 '20 at 19:20
  • Laurentiurad, thanks that you try to help me. I appreciate it. – Archer Jun 25 '20 at 19:25