C#加载JPG文件,提取BitmapImage
发布时间:2020-12-15 04:20:51 所属栏目:百科 来源:网络整理
导读:我试图从JPG中提取Bitmap Image.这是我的代码: FileStream fIn = new FileStream(sourceFileName,FileMode.Open); // source JPGBitmap dImg = new Bitmap(fIn);MemoryStream ms = new MemoryStream();dImg.Save(ms,ImageFormat.Jpeg);image = new BitmapIm
我试图从JPG中提取Bitmap
Image.这是我的代码:
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图像,这当然意味着它不起作用.我该怎么做? 解决方法
尝试这个:
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 } } 或者你可以这样做(source): Bitmap myBmp = Bitmap.FromFile("path here"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |