渲染时某些像素行/列被复制为什么?

时间:2018-06-27 22:58:19

标签: java graphics rendering

我用Java编写了以下测试程序,以尝试调试图形问题。

public class GraphicsDebug extends JPanel{
    private static final long serialVersionUID = 1L;

    public static void main(String[] atgs){
        JFrame frame = new JFrame("GraphicsDebug");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,500);
        frame.add(new GraphicsDebug());
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
    public void paint(Graphics gr){
        int w = getWidth(),h = getHeight(),x = 0,y;
        gr.setColor(Color.BLACK);
        gr.fillRect(0, 0, w, h);
        gr.setColor(Color.WHITE);
        while(x < w){
            y = 0;
            while(y < h){
                gr.fillRect(x, y, 1, 1);
                y += 2;
            }
            x += 2;
        }
    }
}

这就是我得到的:(左侧的红色正方形是放大的部分) I'm starting to understand... 确保以全分辨率查看图像。 测试程序应该使x%2 + y%2 == 0的每个像素都是白色,所有其他像素都是黑色。相反,发生这种情况:

某些行/列的像素在进入我的屏幕之前被复制。 是什么原因导致这个问题,我该如何解决?

0 个答案:

没有答案