Iam*_*mIC 14 c# jpeg bitmap image-processing bitmapimage
我试图从JPG中提取BitmapImage.这是我的代码:
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();
Run Code Online (Sandbox Code Playgroud)
图像以0×0图像返回,这当然意味着它不起作用.我该怎么做呢?
Eug*_*ene 25
试试这个:
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
}
}
Run Code Online (Sandbox Code Playgroud)
或者你可以这样做(来源):
Bitmap myBmp = Bitmap.FromFile("path here");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43772 次 |
| 最近记录: |