试图在winform中放大图像c#

时间:2012-11-11 23:48:51

标签: c# winforms

在button1_Click上,我试图将图像的大小增加10或放大它。但正在发生的事情是,图片框的大小正在增加,图像没有任何变化。如何进行图像缩放。请建议我最简单的方法。

public partial class Form1 : Form
{
public Form1()
{
    InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
    // Construct an image object from a file in the local directory.
    // ... This file must exist in the solution.
    Image image = Image.FromFile("Picture1.png");
    // Set the PictureBox image property to this image.
    // ... Then, adjust its height and width properties.
    pictureBox1.Image = image;
    pictureBox1.Height = image.Height;
    pictureBox1.Width = image.Width;
  }
}
    private void Form1_Load(object sender, EventArgs e)
    {

    }
    private void button1_Click(object sender, EventArgs e)
    {
        pictureBox1.Width += 10;
        pictureBox1.Height +=10;

    }

1 个答案:

答案 0 :(得分:0)

使用PictureBox的SizeMode属性,与您尝试实现的方法相关的简单方法;将它设置为StretchImage。

PictureBox.SizeMode Property - MSDN

但是,一旦你对GDI +(甚至可能是不安全的上下文)感到更舒服,你应该以编程的方式自己做这个以获得更大的灵活性。