我用GraphicsPath定义了一个区域,但用Graphics.FillPath(Brush,GraphicsPath)只能把这个区域用画笔填充,我现在需要的是把这部分图象复制出来,放到其他位置,并且复制出来的要是图象,而不仅仅是轮廓!
请各位指教!

解决方案 »

  1.   

    请问用Graphics.FillRegion方法不会被它的Brush参数指定的画笔填充掉吗?我要的是图象内容不是轮廓
      

  2.   

    你可以使用Graphics.SetClip方法来指定一个区域,然后正常的用Graphics来绘图就可以了,用SetClip方法就是指定Graphics的操作的区域.楼主自己试试看吧.
      

  3.   

    开始我以为你是要画这样的区域,没有说用SetClip方法.
    比如:public void SetClipPath(PaintEventArgs e)
    {    // Create graphics path.
        GraphicsPath clipPath = new GraphicsPath();
        clipPath.AddEllipse(0, 0, 200, 100);    // Set clipping region to path.
        e.Graphics.SetClip(clipPath);    // Fill rectangle to demonstrate clipping region.
        e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
    }
      

  4.   

    //以下示例复制E:\1.JPG的一个椭圆形区域到新建的一个文件E:\2.JPG
    Bitmap bm0 = new Bitmap(@"E:\1.JPG");
    Bitmap bm = new Bitmap(bm0.Width, bm0.Height);
    Graphics g=Graphics.FromImage(bm);
    GraphicsPath gp = new GraphicsPath();
    Rectangle rec = new Rectangle(50,50,120,40);
    gp.AddEllipse(rec);
    g.SetClip(gp,CombineMode.Replace);
    g.DrawImage(bm0,0,0);
    bm.Save(@"E:\2.JPG");
    bm0.Dispose();
    bm.Dispose();
      

  5.   

    可以做验证代码如下:Graphics g = Graphics.FromHwnd(this.pictureBox.Handle);
    GraphicsPath path = new GraphicsPath();
    Image img = Image.FromFile(fileName);path.AddEllipse(this.pictureBox.ClientRectangle);
    g.SetClip(path);
    g.DrawImage(img, this.picDraw.ClientRectangle);
    g.Dispose();
      

  6.   

    现在的CSDN真怪,回帖子的时候明明楼没有见到楼上的老兄啊,呵呵
      

  7.   

    谢谢hbxtlhx(平民百姓)、viena(维也纳N02),通过你们的指点我找到方法了。
    但又有一个问题,不管我用GraphicsPath.AddArc或者AddPie方法添加一个椭圆扇型,此两个方法中的Rectangle参数指定的都是整个圆(椭圆)的宽和高,因此我用AddArc和AddPie画半个椭圆的时候(startAngle和sweepAngle均为180),虽然画出的上半个圆是用Image填充了,但是圆下半部分虽然没有被用图象填充,却用白色覆盖了。
    AddArc和AddPie指定的矩形尺寸是整个圆的尺寸,但是GraphicsPath似乎没有Remove方法能把下半个圆去掉,该如何处理啊??求教了!请看下面图片地址的示例:
    http://www.sayamao.com/test.gif
      

  8.   

    是我搞错了,用Fill白色填充的时候用了椭圆的高度去了,谢谢大家,结帖!