C#加载JPG文件,解压的BitmapImage [英] C# Load JPG file, extract BitmapImage
本文介绍了C#加载JPG文件,解压的BitmapImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图提取一个JPG一个BitmapImage的。这是code我有:
I am trying to extract a BitmapImage from a JPG. This is the code I have:
FileStream fIn = new FileStream(sourceFileName, FileMode.Open); // source JPG
Bitmap dImg = new Bitmap(fIn);
MemoryStream ms = new MemoryStream();
dImg.Save(ms, ImageFormat.Jpeg);
image = new BitmapImage();
image.BeginInit();
image.StreamSource = new MemoryStream(ms.ToArray());
image.EndInit();
ms.Close();
图像回来了0×0的形象,这当然意味着它没有工作。我该怎么做呢?
image comes back with a 0 × 0 image, which of course means it didn't work. How do I do this?
推荐答案
试试这个:
public void Load(string fileName)
{
using(Stream BitmapStream = System.IO.File.Open(fileName,System.IO.FileMode.Open ))
{
Image img = Image.FromStream(BitmapStream);
mBitmap=new Bitmap(img);
//...do whatever
}
}
或者,你可以做到这一点(源):
Bitmap myBmp = Bitmap.FromFile("path here");
这篇关于C#加载JPG文件,解压的BitmapImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文