C#加载JPG文件,提取位图图像
我正在尝试从JPG中提取位图图像。这是我的代码:C#加载JPG文件,提取位图图像,c#,image-processing,bitmap,jpeg,bitmapimage,C#,Image Processing,Bitmap,Jpeg,Bitmapimage,我正在尝试从JPG中提取位图图像。这是我的代码: 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();
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图像,这当然意味着它不工作。我该怎么做?试试这个:
公共无效加载(字符串文件名)
{
使用(Stream BitmapStream=System.IO.File.Open(文件名,System.IO.FileMode.Open))
{
Image img=Image.FromStream(位图流);
mBitmap=新位图(img);
//…做什么都行
}
}
或者您可以这样做():
Bitmap myBmp=Bitmap.FromFile(“此处的路径”);
我发现了错误:我需要使用图像,而不是位图图像。我知道这不需要太复杂!这是工作代码:Image=Image.FromFile(sourceFileName,true);男孩一开始就这么复杂!图像、位图图像、图像源、JPEG图像解码器等。这是我们的工作安全,呵呵:)