如何从图片框中将图像提取为矩形?急需帮助 [英] How to extract the image into a rectangle from the picturebox ? Need help badly

查看:70
本文介绍了如何从图片框中将图像提取为矩形?急需帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
    mybitmap = new Bitmap(pictureBox1.Image);
}

// In the mouse move event
{
    var pixelcolor = mybitmap.GetPixel(e.X, e.Y);
    // Displays R  / G / B Color

    Graphics g = pictureBox1.CreateGraphics();
    g.DrawRectangle(new Pen(Brushes.Blue), 150, 150, 60, 60);
}

推荐答案

1)您无需从pictureBox的Image创建位图。直接使用。

2)不要在鼠标移动事件中画画。相反,请参阅绘制事件 [ ^ 处理程序。 Graphics类的实例[ ^ ]作为参数可用。当然,在那个处理程序中,没有关于绘制内容的信息。因此,使用鼠标移动事件(或/和其他人)在某处存储必要的数据。
1) You don't need to create a bitmap from pictureBox's Image. Use it directly.
2) Don't draw in the mouse move event. Instead, draw in the Paint event[^] handler. An instance of the Graphics class[^] is available there as parameter. Of course, while in that handler, there's no information on what to draw. Therefore use the mouse move event (or/and others) to store necessary data somewhere.


这篇关于如何从图片框中将图像提取为矩形?急需帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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