【问题标题】:How do I get width and heigth of picturebox image coming from ImageLocation?如何获取来自 ImageLocation 的图片框图像的宽度和高度?
【发布时间】:2015-12-25 11:47:16
【问题描述】:

我正在尝试根据图片框中所选图像的分辨率来扩展我的表单。但是,当我更改图像时,图片框的大小似乎没有改变......有什么帮助吗?

pictureBox1.ImageLocation = reader["imagem"].ToString();
pictureBox1.Height = pictureBox1.Image.Height;
pictureBox1.Width = pictureBox1.Image.Width;
/*mw and mh are the main width and main heigth,
 i used this in case the user selects another 
 image, then the window returns to it's original
 size before changing again.*/
this.Height = mh;
this.Width = mw;
this.Height += pictureBox1.Image.Height;
this.Width = pictureBox1.Image.Width + 16;
if (this.Width < mw)
{
    this.Width = mw;
}
this.CenterToParent();

这只是我需要修复的部分代码。其余的都很好,图片框显示我选择的图像,但它没有改变大小。

【问题讨论】:

  • 使用 ImageLocation 没问题,但如果接下来要使用 Image 属性,则必须将 WaitOnLoad 属性设置为 True。或者更好的是,使用 LoadCompleted 事件。

标签: c# picturebox


【解决方案1】:

哦,我刚刚想通了,我改变了

这部分:

pictureBox1.ImageLocation = reader["imagem"].ToString();

至此:

pictureBox1.Image = Image.FromFile(reader["imagem"].ToString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2010-11-18
    • 1970-01-01
    相关资源
    最近更新 更多