C# 視窗程式範例--剪下 PictureBox 中的一塊區域

How to clip a portion of image in a picturebox and display it in another picturebox

The following code clips a portion of image of size width=100 and height=100. It displays a clipped portion in another picture box. To run this code, place two picture boxes in a form and set the image for the first picturebox.



Bitmap ReqdBmp = new Bitmap(100, 100);
Graphics Gra = pictureBox1.CreateGraphics();
Graphics g2 = pictureBox2.CreateGraphics();
g2.DrawImage(pictureBox1.Image, new Rectangle(0, 0, ReqdBmp.Width, ReqdBmp.Height), new Rectangle(100, 100, ReqdBmp.Width, ReqdBmp.Height), GraphicsUnit.Pixel);

Responses to "How to clip a portion of image in a picturebox and display it in another picturebox"
Author: Neeraj Saluja  12 May 2008   Member Level: Gold   Points : 2
The code is not appearing completely. It should be

Bitmap ReqdBmp = new Bitmap(100, 100);
Graphics Gra = pictureBox1.CreateGraphics();
Graphics g2 = pictureBox2.CreateGraphics();
g2.DrawImage(pictureBox1.Image, new Rectangle(0, 0, ReqdBmp.Width, ReqdBmp.Height), new Rectangle(100, 100, ReqdBmp.Width, ReqdBmp.Height), GraphicsUnit.Pixel);


http://www.dotnetspider.com/resources/15891-How-cl...

陳鍾誠 (2011年12月20日),(網頁標題) 剪下 PictureBox 中的一塊區域,(網站標題) 免費電子書:C# 程式設計,2011年12月20日,取自 http://cs0.wikidot.com/clippicturebox ,網頁修改第 0 版。

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()