gdi+如何复制图片中的一个不规则区域,并将其绘制到其他位置?在线急等 我用GraphicsPath定义了一个区域,但用Graphics.FillPath(Brush,GraphicsPath)只能把这个区域用画笔填充,我现在需要的是把这部分图象复制出来,放到其他位置,并且复制出来的要是图象,而不仅仅是轮廓!请各位指教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请问用Graphics.FillRegion方法不会被它的Brush参数指定的画笔填充掉吗?我要的是图象内容不是轮廓 你可以使用Graphics.SetClip方法来指定一个区域,然后正常的用Graphics来绘图就可以了,用SetClip方法就是指定Graphics的操作的区域.楼主自己试试看吧. 开始我以为你是要画这样的区域,没有说用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);} //以下示例复制E:\1.JPG的一个椭圆形区域到新建的一个文件E:\2.JPGBitmap 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(); 可以做验证代码如下: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(); 现在的CSDN真怪,回帖子的时候明明楼没有见到楼上的老兄啊,呵呵 谢谢hbxtlhx(平民百姓)、viena(维也纳N02),通过你们的指点我找到方法了。但又有一个问题,不管我用GraphicsPath.AddArc或者AddPie方法添加一个椭圆扇型,此两个方法中的Rectangle参数指定的都是整个圆(椭圆)的宽和高,因此我用AddArc和AddPie画半个椭圆的时候(startAngle和sweepAngle均为180),虽然画出的上半个圆是用Image填充了,但是圆下半部分虽然没有被用图象填充,却用白色覆盖了。AddArc和AddPie指定的矩形尺寸是整个圆的尺寸,但是GraphicsPath似乎没有Remove方法能把下半个圆去掉,该如何处理啊??求教了!请看下面图片地址的示例:http://www.sayamao.com/test.gif 是我搞错了,用Fill白色填充的时候用了椭圆的高度去了,谢谢大家,结帖! 关于webbrowser获取html源文件的几个问题 多个combox,选中的选项其他combox中不显示与改变选项时恢复选项的问题 求累加和校验算法 c#怎么控制 EPSON 630K USB口问题 C#字符串数组 求助!! 求局域网内部使用的类似QQ的在线聊天工具源代码,解决问题的话再开贴放分 控件错误: WindowsApplication6.Form1.label1”表示“字段”,此处应为“类” 简单正则表达式 c#中求余数的函数是什么? 紧急求救,mm安装.NET framework2.0百年不遇的问题?分不够再加。 在vs2005的帮助里点“提出问题”,这个链接竟然指向...
比如: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);
}
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();
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();
但又有一个问题,不管我用GraphicsPath.AddArc或者AddPie方法添加一个椭圆扇型,此两个方法中的Rectangle参数指定的都是整个圆(椭圆)的宽和高,因此我用AddArc和AddPie画半个椭圆的时候(startAngle和sweepAngle均为180),虽然画出的上半个圆是用Image填充了,但是圆下半部分虽然没有被用图象填充,却用白色覆盖了。
AddArc和AddPie指定的矩形尺寸是整个圆的尺寸,但是GraphicsPath似乎没有Remove方法能把下半个圆去掉,该如何处理啊??求教了!请看下面图片地址的示例:
http://www.sayamao.com/test.gif