如何剪辑图像的一部分 [英] How to Clip a portion of an Image

查看:130
本文介绍了如何剪辑图像的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,


我有一张图片。我想剪辑一部分并复制到另一张图片。

如何做到这一点?我知道要剪辑的边界矩形。


请给我任何建议。


感谢您的时间和帮助。

问候

Anand Ganesh

解决方案

从位图创建图形对象并使用

来自其他图形对象的图像。你可以指定来源和

dest rects。


Jonathan Schafer


周五,2003年7月11日18 :49:11 -0700,Anand Ganesh

< an ********** @ hotmail.com>写道:

HI全部,

我有一个图像。我想剪辑它的一部分并复制到另一个图像。
如何做到这一点?我知道要剪辑的边界矩形。

请提出任何建议。

感谢您的时间和帮助。

问候
Anand Ganesh




我试过这个但是我收到了一个错误

类型''System.Exception'的未处理异常'发生在

system.drawing.dll


附加信息:无法从图像创建图形对象

一个索引的像素格式。

但问题是剪辑后我需要另一个Image对象本身。

目的地应该是图像,但是imae应该是

更大图像的剪裁图像。


任何更多建议对吗?


问候

Anand Ganesh

" Jonathan Schafer" < jschafer@*NOSPAM*brierley.a.b.c.com>在留言中写道

news:q5 ******************************** @ 4ax.com ...

从位图创建图形对象,并使用其他图形对象的
图像绘制到该图形对象中。你可以指定来源和
目标。

Jonathan Schafer

2003年7月11日星期五18:49:11 -0700,Anand Ganesh
< an ********** @ hotmail.com>写道:

HI全部,

我有一个图像。我想剪辑它的一部分并复制到另一个
图像。如何做到这一点?我知道要剪辑的边界矩形。

请提出任何建议。

感谢您的时间和帮助。

问候
Anand Ganesh



以下代码适用于我。它加载.gif,将gif的30 x 30

部分绘制到屏幕外位图中,然后将缩放的

图像绘制到图片框中。


System.Drawing.Bitmap bmp = new Bitmap(30,30);

Image

img = System.Drawing.Image.FromFile( @" C:\ cygwin \ bin \ openssl-0.9.6d\doc\openssl_button.gif");

图形g1 = pictureBox1.CreateGraphics();

g1.DrawImage(img,0,0,img.Width,img.Height);

g1.Dispose();

图形g3 =图形。 FromImage(bmp);

g3.DrawImageUnscaled(img,0,0,bmp.Width,bmp.Height);

Graphics g2 = pictureBox2.CreateGraphics();

g2.DrawImageUnscaled(bmp,0,0,bmp.Width,bmp.Height);

g2.Dispose();

g3。 Dispose();

bmp.Dispose();

img.Dispose();

Jonathan Schafer


On Sun,2003年7月13日21:53:20 -0700,Anand Ganesh

< an ********** @ hotmail.co米>写道:

我试过这个但是我收到了一个错误


系统中发生了'System.Exception'类型的未处理异常。 drawing.dll

附加信息:无法从具有索引像素格式的图像创建图形对象。

但问题是剪切后我需要另一个Image对象本身。
目的地应该是一个图像,但是图像应该是更大图像的剪切图像。

还有更多的建议吗?

关心< Anand Ganesh

" Jonathan Schafer" < jschafer@*NOSPAM*brierley.a.b.c.com>在消息中写道
新闻:q5 ******************************** @ 4ax.com ..。< blockquote class =post_quotes>从位图创建图形对象并使用其他图形对象的
图像绘制到该图形对象中。你可以指定来源和
目标。

Jonathan Schafer

2003年7月11日星期五18:49:11 -0700,Anand Ganesh
< an ********** @ hotmail.com>写道:

>全部,
>
>我有一个图像。我想剪辑它的一部分并复制到另一个图像。 >怎么做?我知道要剪辑的边界矩形。
>
>请提出任何建议。
>
>感谢您的时间和帮助。
>
>问候
> Anand Ganesh
>




HI All,

I have an Image. I want to clip a portion of it and copy to another image.
How to do this? I know the bounding rectangle to clip.

Any suggestions please.

Thanks for your time and help.

Regards
Anand Ganesh

解决方案

Create a graphics object from a bitmap and draw into it using the
image from the other graphics object. You can specify the source and
dest rects.

Jonathan Schafer

On Fri, 11 Jul 2003 18:49:11 -0700, "Anand Ganesh"
<an**********@hotmail.com> wrote:

HI All,

I have an Image. I want to clip a portion of it and copy to another image.
How to do this? I know the bounding rectangle to clip.

Any suggestions please.

Thanks for your time and help.

Regards
Anand Ganesh




I tried this but I got an error
An unhandled exception of type ''System.Exception'' occurred in
system.drawing.dll

Additional information: A Graphics object cannot be created from an image
that has an indexed pixel format.
But the problem is after clipping I need another Image object itself. The
destination should be an image but the imae should be a clipped image of the
bigger Image.

Any more suggestions please?

Regards
Anand Ganesh
"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:q5********************************@4ax.com...

Create a graphics object from a bitmap and draw into it using the
image from the other graphics object. You can specify the source and
dest rects.

Jonathan Schafer

On Fri, 11 Jul 2003 18:49:11 -0700, "Anand Ganesh"
<an**********@hotmail.com> wrote:

HI All,

I have an Image. I want to clip a portion of it and copy to another image.How to do this? I know the bounding rectangle to clip.

Any suggestions please.

Thanks for your time and help.

Regards
Anand Ganesh



The following code works for me. It loads a .gif, draws the 30 x 30
section of the gif into an offscreen bitmap, and then draws the scaled
image into a picturebox.

System.Drawing.Bitmap bmp = new Bitmap(30, 30);
Image
img=System.Drawing.Image.FromFile(@"C:\cygwin\bin\ openssl-0.9.6d\doc\openssl_button.gif");
Graphics g1 = pictureBox1.CreateGraphics();
g1.DrawImage(img, 0, 0, img.Width, img.Height);
g1.Dispose();
Graphics g3 = Graphics.FromImage(bmp);
g3.DrawImageUnscaled(img, 0, 0, bmp.Width, bmp.Height);
Graphics g2 = pictureBox2.CreateGraphics();
g2.DrawImageUnscaled(bmp, 0, 0, bmp.Width, bmp.Height);
g2.Dispose();
g3.Dispose();
bmp.Dispose();
img.Dispose();
Jonathan Schafer

On Sun, 13 Jul 2003 21:53:20 -0700, "Anand Ganesh"
<an**********@hotmail.com> wrote:

I tried this but I got an error
An unhandled exception of type ''System.Exception'' occurred in
system.drawing.dll

Additional information: A Graphics object cannot be created from an image
that has an indexed pixel format.
But the problem is after clipping I need another Image object itself. The
destination should be an image but the imae should be a clipped image of the
bigger Image.

Any more suggestions please?

Regards
Anand Ganesh
"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:q5********************************@4ax.com.. .

Create a graphics object from a bitmap and draw into it using the
image from the other graphics object. You can specify the source and
dest rects.

Jonathan Schafer

On Fri, 11 Jul 2003 18:49:11 -0700, "Anand Ganesh"
<an**********@hotmail.com> wrote:

>HI All,
>
>I have an Image. I want to clip a portion of it and copy to anotherimage. >How to do this? I know the bounding rectangle to clip.
>
>Any suggestions please.
>
>Thanks for your time and help.
>
>Regards
>Anand Ganesh
>




这篇关于如何剪辑图像的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆