自动调整图片框中的图像

时间:2012-11-15 09:44:39

标签: c# image

我正在做一个imageviewer。我已经完成了在图片框中导入图像。

应该使用哪些代码来自动调整图片框中的图像?这是我在查看图片框中的图片中的代码。

  private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Multiselect = true;
        openFileDialog.Filter = "JPEG|*.jpg|Bitmaps|*.bmp";

        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            pFileNames = openFileDialog.FileNames;
            pCurrentImage = 0;
            ImageView();
        }
    }

    protected void ImageView()
    {
        if (pCurrentImage >= 0 && pCurrentImage <= pFileNames.Length - 1)
        {
            pictureBox1.Image = Bitmap.FromFile(pFileNames[pCurrentImage]);
        }
    }

3 个答案:

答案 0 :(得分:9)

查看SizeMode的{​​{1}}属性:http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode.aspx

将此设置为PictureBox,您就可以开始了。

Check here what you can set it to

答案 1 :(得分:2)

检查PictureBox.SizeMode Property并按PictureBoxSizeMode Enumeration设置它,因为您希望PictureBox控件在显示图像时执行此操作。

  • AutoSize意味着PictureBox将适合图像。

如果您想要图片适合pictureBox,请将sizemode设置为 StretchImage

// Set the SizeMode property to the StretchImage value.  
// This will enlarge the image as needed to fit into 
// the PictureBox.
    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

答案 2 :(得分:0)

您可以尝试将PictureBox上的SizeMode属性设置为AutoSize。

相关问题