从url加载图像到picturebox背景

时间:2021-09-20 00:23:45

I found some easy ways to load image to picturebox but I couldn't find an easy way to load image to picturebox backround.

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

If you know any easier example than this...

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

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);
}

...please share it.

...请分享。

The two easy ways to load image from url to picturebox are...

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

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

pictureBox1.Load(url);

But I cannot use them

但我不能使用它们

The reason that I want to use BackroundImage instead of Image is that I want to stretch the image.

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

2 个解决方案

#1


1  

If you want to strech your image to fit the PictureBox you can PictureBox.SizeMode to StretchImage.

如果要拉伸图像以适合PictureBox,可以将PictureBox.SizeMode拉伸到StretchImage。

This will work when you specify your image using the pictureBox1.ImageLocation property or the pictureBox1.Load() method.

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

#2


1  

As easy as :

一样容易 :

pictureBox1.BackgroundImage=your_Image;

pictureBox1.BackgroundImage = your_Image;

For more info check here

有关更多信息,请点击此处

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

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

or

要么

2. Picture Box have both Image and Background Image Property

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

to set Background Image you have to set pictureBox1.BackgroundImage=your_Image;

设置背景图像你必须设置pictureBox1.BackgroundImage = your_Image;

and for Image property pictureBox1.Image=your_Image; from here: PictureBox BackgroundImage Property C#

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

#1


1  

If you want to strech your image to fit the PictureBox you can PictureBox.SizeMode to StretchImage.

如果要拉伸图像以适合PictureBox,可以将PictureBox.SizeMode拉伸到StretchImage。

This will work when you specify your image using the pictureBox1.ImageLocation property or the pictureBox1.Load() method.

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

#2


1  

As easy as :

一样容易 :

pictureBox1.BackgroundImage=your_Image;

pictureBox1.BackgroundImage = your_Image;

For more info check here

有关更多信息,请点击此处

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

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

or

要么

2. Picture Box have both Image and Background Image Property

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

to set Background Image you have to set pictureBox1.BackgroundImage=your_Image;

设置背景图像你必须设置pictureBox1.BackgroundImage = your_Image;

and for Image property pictureBox1.Image=your_Image; from here: PictureBox BackgroundImage Property C#

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