开贴求助.还是剪切图片.

krisviper 2010-07-13 03:43:55
在图片上画个线框,然后拖动这个线框,拖动线框会很卡.请问怎么解决?

如图:


代码:


private void pictureBox_Pic_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Blue, 1);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
Rectangle rect = new Rectangle(mPoint1, new Size(mPoint2.X - mPoint1.X, mPoint2.Y - mPoint1.Y));
e.Graphics.DrawRectangle(p, rect);
}



QQ:100620205 (欢迎即时交流).
...全文
114 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
krisviper 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 hiddkiller 的回复:]

我以前做得有一个.
http://topic.csdn.net/u/20071220/17/d40930c4-93d8-41d8-8d64-28d744499ff7.html
[/Quote]


效果确实是这种效果. 但是鼠标不动之后 线框会消失.请问怎么解决?
hiddkiller 2010-07-14
  • 打赏
  • 举报
回复
我以前做得有一个.
http://topic.csdn.net/u/20071220/17/d40930c4-93d8-41d8-8d64-28d744499ff7.html
dylike 2010-07-14
  • 打赏
  • 举报
回复
paint中绘制很闪属于正常现象.如要不闪则用贴图
krisviper 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 takemoto 的回复:]

楼主,2楼的方法才是你想要的;写了段代码其他的你自己实现吧!
C# code

public partial class MyPictureBox : UserControl
{
bool mouseDown;
Point startPoint = Point.Empty;
Rectangle mouseRect = Rectangle……
[/Quote]


用你给的方法,画框的时候会非常的闪,请问能解决吗?
takemoto 2010-07-13
  • 打赏
  • 举报
回复
楼主,2楼的方法才是你想要的;写了段代码其他的你自己实现吧!

public partial class MyPictureBox : UserControl
{
bool mouseDown;
Point startPoint = Point.Empty;
Rectangle mouseRect = Rectangle.Empty;

public MyPictureBox()
{
InitializeComponent();
}

public Bitmap Image { get; set; }

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);

this.Capture = true;
this.mouseDown = true;

this.startPoint = new Point(e.X, e.Y);
this.mouseRect = new Rectangle(e.X, e.Y, 0, 0);
Cursor.Clip = this.RectangleToScreen(this.ClientRectangle);
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);

if (this.mouseDown)
{
this.ResizeRectangle(e.Location);
}
}

protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);

if (this.mouseDown)
{
this.Capture = false;
this.mouseDown = false;

Cursor.Clip = Rectangle.Empty;

this.DrawReversibleFrame();

this.mouseRect = Rectangle.Empty;

this.DrawReversibleFrame();

}
}

void ResizeRectangle(Point p)
{
this.DrawReversibleFrame();

this.mouseRect.Width = p.X - mouseRect.Left;
this.mouseRect.Height = p.Y - mouseRect.Top;

this.DrawReversibleFrame();
}

void DrawReversibleFrame()
{
Rectangle rect = this.RectangleToScreen(this.mouseRect);

ControlPaint.DrawReversibleFrame(rect, Color.Yellow, FrameStyle.Thick);
}
}

hiddkiller 2010-07-13
  • 打赏
  • 举报
回复
看这个帖子
http://topic.csdn.net/u/20100712/12/fd2f26eb-fb8a-4f83-85aa-db5adaff2aee.html

他的是画 十字线 你的是画矩形框, 其实是一个道理.
kolosi 2010-07-13
  • 打赏
  • 举报
回复
我觉得你说的状况是由于你mousemove事件写的不对,贴出来看看。
krisviper 2010-07-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hiddkiller 的回复:]
在鼠标移动事件要触发 pictureBox 重绘,且在pictureBox重绘里要去掉之前的线框.
[/Quote]

大侠加个qq指教一下把. 100620205
krisviper 2010-07-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hiddkiller 的回复:]
在鼠标移动事件要触发 pictureBox 重绘,且在pictureBox重绘里要去掉之前的线框.
[/Quote]

触发重绘.

用这个函数? this.pictureBox_Pic.Invalidate();
hiddkiller 2010-07-13
  • 打赏
  • 举报
回复
在鼠标移动事件要触发 pictureBox 重绘,且在pictureBox重绘里要去掉之前的线框.
wl076 2010-07-13
  • 打赏
  • 举报
回复
遇到同样的问题,坐等高手来解答!
krisviper 2010-07-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gomoku 的回复:]
建议用ControlPaint.DrawReversibleFrame,而不是重画PictureBox
[/Quote]

你好.我说的很慢不是系统很慢.
我是指线框的移动速度很慢,鼠标一托快点,就不同步了(鼠标跑很远了,线框还在后面.)
gomoku 2010-07-13
  • 打赏
  • 举报
回复
建议用ControlPaint.DrawReversibleFrame,而不是重画PictureBox

110,536

社区成员

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

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

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