Java:基本绘图,绘制点/点/像素

Dmi*_*mov 5 java graphics plot drawing pixel

我需要有一个面板,我可以在其中绘制.我希望能够逐像素地绘制.

ps:我不需要其他基元的行/圆.pps:图形库并不重要,它可以是awt,swing,qt ......任何东西.我只想要一些通常由Bufferedimage表示的东西,或者像你设置单个像素颜色然后将其渲染到屏幕上的东西.

Joo*_*ool 5

一种方法的示例:

// Create the new image needed
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB );

for ( int rc = 0; rc < height; rc++ ) {
  for ( int cc = 0; cc < width; cc++ ) {
    // Set the pixel colour of the image n.b. x = cc, y = rc
    img.setRGB(cc, rc, Color.BLACK.getRGB() );
  }//for cols
}//for rows
Run Code Online (Sandbox Code Playgroud)


然后从重写的paintComponent(Graphics g)中

((Graphics2D)g).drawImage(img, <args>)
Run Code Online (Sandbox Code Playgroud)


And*_*son 2

由 Bufferedimage 表示..

我建议BufferedImage为此,显示..

..或者类似的东西,您设置单个像素的颜色,然后将其渲染到屏幕上。

..在a-如这个答案JLabel中所示。

当然,一旦我们有了 的实例BufferedImage,我们就可以setRGB(..)