在PictureBox中缩放图片

时间:2015-04-27 09:56:13

标签: c# winforms visual-studio

我在PictureBox控件中有一张图片和一行。我知道如何使用以下代码缩放图片:

private void pictureBox1_Click(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        if (Globals.x == 1)
        {
            Globals.y = 1;
            Globals.a = e.X;
            Globals.b = e.Y;
        }
    }
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    // Create a local version of the graphics object for the PictureBox.
    Graphics g = e.Graphics;
    if (Globals.y == 0)
    {
        e.Graphics.DrawImage(bitmap, 0, 0, 470, 353);
        e.Graphics.DrawLine(System.Drawing.Pens.Red, 210, 66, 112, 122);
        e.Graphics.DrawLine(System.Drawing.Pens.Red, 112, 122, 15, 205);
    }

    Bitmap bmpZoom = new Bitmap(bitmap.Width, bitmap.Height);
    int new4W = bitmap.Width / 3;
    int new4H = bitmap.Height / 3;
    int new2W = bitmap.Width *2/ 3;
    int new2H = bitmap.Height *2/ 3;
    Rectangle srcRect = new Rectangle(Globals.a - new4W,Globals.b - new4H, new2W, new2H);
    Rectangle dstRect = new Rectangle(60, 10, bmpZoom.Width, bmpZoom.Height);
}

我的代码可以缩放我点击的图片部分,但是当我再次尝试绘制线条时,它就在同一个位置(这是正常的)。

我想要一个可以缩放图片和线条的解决方案。如果有人能帮助我,我会很高兴。

0 个答案:

没有答案
相关问题