选择图像区域 [英] Select Area of Image

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

问题描述

我正在尝试使用openfiledialog选择我选择的图像区域
我想要选择的区域是xx的16x16,y坐标5,5
一旦选择了我想要的将16x16图像绘制到坐标0,0处的另一个pictureBox中

I'm trying to select an area of an image I've selected using openfiledialog The area I'm trying to select is 16x16 from x,y coordinates 5,5 Once selected I want to draw the 16x16 image into another pictureBox at coordinates 0,0

这是我得到的代码,但我无法选择正确的部分原始图片,有人建议为什么它不起作用?

This is the code I've got but I can't get it to select the correct part of the original image, anybody any suggestions as to why it doesn't work?

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);
}


推荐答案

为了选择正确的部分,只需替换:

In order to select the correct section, just replace:

g3.DrawImageUnscaled(origImage, 0, 0, 16, 16);

with

g3.DrawImageUnscaled(origImage, -5, -5, 16, 16);

这篇关于选择图像区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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