【发布时间】:2013-01-10 08:28:40
【问题描述】:
我正在尝试选择我使用 openfiledialog 选择的图像区域 我要选择的区域是 x,y 坐标 5,5 的 16x16 选择后,我想将 16x16 图像绘制到坐标 0,0 处的另一个图片框
这是我得到的代码,但我无法让它选择原始图像的正确部分,有人对它为什么不起作用有任何建议吗?
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
Image origImage = Image.FromFile(openFileDialog1.FileName);
pictureBoxSkin.Image = origImage;
lblOriginalFilename.Text = openFileDialog1.SafeFileName;
System.Drawing.Bitmap bmp = new Bitmap(16, 16);
Graphics g3 = Graphics.FromImage(bmp);
g3.DrawImageUnscaled(origImage, 0, 0, 16, 16);
Graphics g2 = pictureBoxNew.CreateGraphics();
g2.DrawImageUnscaled(bmp, 0, 0, 16, 16);
}
【问题讨论】:
-
您能否详细说明它是如何不工作的?
-
使用 Graphics.DrawImage(Image, Rectangle, Rectangle, GraphicsUnit) 重载。