0

我找到了一些将图像加载到图片框的简单方法,但我找不到将图像加载到图片框背景的简单方法。

如果你知道比这更简单的例子......

var request = WebRequest.Create("http://www.example.com/image.jpg");

using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
    pictureBox1.BackroundImage = Bitmap.FromStream(stream);
}

...请分享。

将图像从 url 加载到图片框的两种简单方法是...

pictureBox1.ImageLocation = "http://www.example.com/image.jpg";

pictureBox1.Load(url);

但我不能使用它们

我想使用BackroundImage而不是Image的原因是我想拉伸图像。

4

2 回答 2

1

一样容易 :

pictureBox1.BackgroundImage=your_Image;

欲了解更多信息,请查看此处

1. http://msdn.microsoft.com/en-us/library/system.windows.forms.control.backgroundimage.aspx

或者

2. 图片框同时具有图像和背景图像属性

要设置背景图像,您必须设置 pictureBox1.BackgroundImage=your_Image;

对于 Image 属性 pictureBox1.Image=your_Image; 从这里开始:PictureBox BackgroundImage 属性 C#

于 2012-10-17T23:40:41.527 回答
1

如果您想拉伸图像以适合 PictureBox,您PictureBox.SizeMode可以StretchImage.

当您使用pictureBox1.ImageLocation属性或pictureBox1.Load()方法指定图像时,这将起作用。

于 2012-10-17T23:42:18.440 回答