Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#加载JPG文件,提取位图图像_C#_Image Processing_Bitmap_Jpeg_Bitmapimage - Fatal编程技术网

C#加载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();

我正在尝试从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();
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图像解码器等。这是我们的工作安全,呵呵:)