如何将图像更改为图片框的大小?

时间:2012-12-13 22:43:38

标签: c# image

正如标题所说,我看不出为什么图像没有改变尺寸。有谁能看到?

{
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open bitmap or jpeg.";
            //dlg.Filter = "jpg files (*.jpg);*.jpg;*.* | bmp files (*.bmp); *.bmp";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.pictureBoxMap1.Image = new Bitmap(dlg.OpenFile());
                Image newImage = this.pictureBoxMap1.Image;
                pictureBoxMap1.Height = newImage.Height;
                pictureBoxMap1.Width = newImage.Width;
            }
            dlg.Dispose();

1 个答案:

答案 0 :(得分:3)

        OpenFileDialog fd = new OpenFileDialog();
        DialogResult r = fd.ShowDialog();
        if (r == System.Windows.Forms.DialogResult.OK)
        {
            pictureBoxMap1.Image = Bitmap.FromFile(fd.FileName);
            pictureBoxMap1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBoxMap1.Refresh();
       }

试试这个。