我的.png图片以Uri对象存储,并且具有以下格式
"pack://application:,,,/AppName.Modules.App.Shared;component/Images/AppName_logo.png"
我该如何将这个图像加载到
System.Drawing.Bitmap
对象中?BitmapImage
,然后进行转换。BitmapImage bi = new BitmapImage(
new Uri("pack://application:,,,/AppName.Modules.App.Shared;component/Images/AppName_logo.png"));
Bitmap b = BitmapImage2Bitmap(bi);
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
return new Bitmap(bitmap);
}
}