矩形框选择放大图片

dzhl01 2009-03-24 11:00:37
我用picturebox调入图片,如何像acdsee实现用鼠标在图片上拖出一个虚矩形,然后将该部分放大
...全文
107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huwei001982 2009-03-25
  • 打赏
  • 举报
回复
pic 是一个 picture 控件, 将它的SizeMode 设置为 StretchImage
huwei001982 2009-03-25
  • 打赏
  • 举报
回复
Rectangle rect;
Point pt = new Point();
bool mouse = false;
private void pic_MouseDown(object sender, MouseEventArgs e)
{
mouse = true;
pt = pic.PointToScreen(e.Location);
rect = new Rectangle(0, 0, 0, 0);
}

private void pic_MouseMove(object sender, MouseEventArgs e)
{
if (!mouse)
return;
ControlPaint.DrawReversibleFrame(rect, Color.Red, FrameStyle.Thick);
Point pt2 = pic.PointToScreen(e.Location);
rect = new Rectangle(pt, new Size(pt2.X - pt.X, pt2.Y - pt.Y));
ControlPaint.DrawReversibleFrame(rect, Color.Red, FrameStyle.Thick);
}

private void pic_MouseUp(object sender, MouseEventArgs e)
{
mouse = false;
Point pt2 = pic.PointToScreen(e.Location);
rect = new Rectangle(pt, new Size(pt2.X - pt.X, pt2.Y - pt.Y));
ControlPaint.DrawReversibleFrame(rect, Color.Red, FrameStyle.Thick);

//放大图片
float perWidth = pic.Width / (float)rect.Width;
float perHeight = pic.Height / (float)rect.Height;
pic.Width = (int)(pic.Width * perWidth);
pic.Height = (int)(pic.Height * perHeight);
dzhl01 2009-03-25
  • 打赏
  • 举报
回复
huwei001982给出的方法又时间也研究下,虽还不知正确与否,看出代码的份上,也要给分
tommir3 2009-03-24
  • 打赏
  • 举报
回复
切割图片,如果保存,再显示。
看人做过,不过没要过原码。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧