I have a BitmapImage object loaded with an icon, I need to convert that to StdPicture . How do I do that ?
I found tons of examples on how to convert System.Drawing.Image to StdPicture but nothing for System.Windows.Media.Imaging.BitmapImage to StdPicture .
Do I have to first convert it to Winforms Image and then to StdPicture ? Sounds a bit silly to me.
I am assuming stdPicture you mean Bitmap.. So here we go.
private Bitmap BitmapImageToBitmap(BitmapImage bitmapImage)
{
using (MemoryStream os = new MemoryStream())
{
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
encoder.Save(os);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(os);
return new Bitmap(bitmap);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.