[英]Loading an image in the PictureBox and draw a rectangle
我写了这段代码:
private void ResizeImage()
{
SetImage(Image);
}
private void SetPen()
{
CreatePen(10,10,20,60);
}
private void CreatePen(int x, int y, int width, int height)
{
Rectangle = new Rectangle(x, y, width, height);
Pen = new Pen(Color.Crimson, 1);
(Image.CreateGraphics()).DrawRectangle(Pen, Rectangle);
Invalidate();
}
问题在于方法Load()将图像替换为矩形。 我正在做图像Cropper,用户无法在其中创建新选择。 该程序将自己创建选择,用户只能移动它。
在PictureBox的Paint事件中绘制矩形:
void PictureBox_Paint(object sender, PaintEventArgs e)
{
Rectangle = new Rectangle(x, y, width, height);
Pen = new Pen(Color.Crimson, 1);
e.Graphics.DrawRectangle(Pen, Rectangle);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.