将图像转换为位图 [英] Convert Image to Bitmap
本文介绍了将图像转换为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将图像文件转换为位图。
我无法转换。
我试过这个:
位图(ImageFile)
How to convert an image file to Bitmap.
I am not able to convert.
I tried this:
Bitmap(ImageFile)
推荐答案
尝试下面的一个。
Try below one.
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
// BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));
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 bitmap; <-- leads to problems, stream is closed/closing ...
return new Bitmap(bitmap);
}
}
欲了解更多信息:将BitmapImage转换为Bitmap,反之亦然
我希望这会帮助你。
For more info : Converting BitmapImage to Bitmap and vice versa
I hope this will help to you.
这对我来说......
位图bm =新位图(路径+文件名+。jpg );
This is done for me...
Bitmap bm = new Bitmap(path+filename+".jpg");
一个类似的问题被问到这里 [ ^ ]。
A similar question was asked here[^].
>
这篇关于将图像转换为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文