当前绘图区已绘制出图形,如何取得它的图形对象,想把它复制到另一个Image,有没有一个类似于WinAPI中的BitBlt的方法将它复制出来。

解决方案 »

  1.   

    g 是Graphics对象g.copyArea(int x, int y, int width, int height, int dx, int dy)可以在把一个区域的图像copy到其他位置
      

  2.   

    感谢steven,我的目的是要复制到其它画布,这样可以吗?麻烦你再解释一下.
      

  3.   

    int[] pixels = new int[w * h];
     PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
     try {
         pg.grabPixels();
     } catch (InterruptedException e) {
         System.err.println("interrupted waiting for pixels!");
         return;
     }
    ImageProducer ip = new MemoryImageSource(w, h, pix, 0, w);
    Image copImg = createImage(ip);
    你看看这段代码行吗,PixelGrabber对象抓取一定区域的象素存在int数组里,然后利用MemoryImageSource从这个象素数组里构建图片。