【问题标题】:Loading an image in the PictureBox and draw a rectangle在 PictureBox 中加载图像并绘制一个矩形
【发布时间】:2011-12-25 20:35:59
【问题描述】:

我写了这段代码:

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() 将图像替换为矩形。我正在做图像裁剪器,用户无法创建新的选择。程序自己创建选择,用户只能移动它。

【问题讨论】:

    标签: c# image picturebox crop drawrectangle


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-07-06
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2014-12-11
      • 1970-01-01
      • 2017-06-09
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多