我有一个a的实例,System.Drawing.Bitmap并希望以一种形式将它提供给我的WPF应用程序System.Windows.Media.Imaging.BitmapImage.
对此最好的方法是什么?
我想加载这样的图像:
void info(string channel)
{
//Something like that
channelPic.Image = Properties.Resources.+channel
}
Run Code Online (Sandbox Code Playgroud)
因为我不想这样做
void info(string channel)
{
switch(channel)
{
case "chan1":
channelPic.Image = Properties.Resources.chan1;
break;
case "chan2":
channelPic.Image = Properties.Resources.chan2;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
这样的事情可能吗?
我不知道我是否正确,但基本上发生了什么是我创建了一个winform应用程序从资源文件夹加载其图像..问题是,当我构建项目并获得exe并将其提供给朋友,他不会像我那样拥有那个资源文件夹,所以他会收到一个错误说丢失文件.
我怎么能以某种方式混合,组合或附加图像与我的应用程序?
我在项目的资源文件夹中有一些图像,但我想从项目的这些资源文件中更改图片框
为什么我不能从try块中返回我从url获得的图像?对不起英语不好:(.
这是我得到的错误:
退货声明丢失
public static Image GetExternalImg(string name, string size)
{
try
{
// Get the image from the web.
WebRequest req = WebRequest.Create(String.Format("http://www.picturesite.com/picture.png", name, size));
// Read the image that we get in a stream.
Stream stream = req.GetResponse().GetResponseStream();
// Save the image from the stream that we are rreading.
Image img = Image.FromStream(stream);
// Save the image to local storage.
img.Save(Environment.CurrentDirectory + "\\images\\" + name + ".png");
return img;
}
catch (Exception)
{
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,因为我现在卡住了:(.