My .png image is stored on a Uri object and it has the following format
"pack://application:,,,/AppName.Modules.App.Shared;component/Images/AppName_logo.png"
How do I load this image onto a System.Drawing.Bitmap
object?
My .png image is stored on a Uri object and it has the following format
"pack://application:,,,/AppName.Modules.App.Shared;component/Images/AppName_logo.png"
How do I load this image onto a System.Drawing.Bitmap
object?
Assuming you are using WPF, you can first load the image as a BitmapImage
and then convert it.
See this answer to "Converting BitmapImage to Bitmap and vice versa"
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);
}
}