Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 下载图像并用作资源_C#_Image_Downloadfile - Fatal编程技术网

C# 下载图像并用作资源

C# 下载图像并用作资源,c#,image,downloadfile,C#,Image,Downloadfile,在WPF C#中,我在运行时使用.DownloadFile()方法从网络下载图像,并将其保存在名为“\images\downloatedposters\”的特定文件夹中,但当我尝试在以图像路径作为URL的编程生成的UI元素中使用它们时,它根本不显示图像 我认为这是因为映像没有将BuildAction类型设置为资源 我该如何应对?我必须将下载的图像也嵌入到资源文件中吗?给你:。 使用此加载例程: var bitmapImage = new BitmapImage(); bitmapImage.Be

在WPF C#中,我在运行时使用.DownloadFile()方法从网络下载图像,并将其保存在名为“\images\downloatedposters\”的特定文件夹中,但当我尝试在以图像路径作为URL的编程生成的UI元素中使用它们时,它根本不显示图像

我认为这是因为映像没有将BuildAction类型设置为资源

我该如何应对?我必须将下载的图像也嵌入到资源文件中吗?

给你:。 使用此加载例程:

var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri("img.jpg", UriKind.Relative);
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
img.Source = bitmapImage;

这是WinForms的解决方案吗?WPF?WPF C#对不起,忘了提了