gpt4 book ai didi

C#加载JPG文件,提取BitmapImage

转载 作者:可可西里 更新时间:2023-11-01 08:04:49 25 4
gpt4 key购买 nike

我正在尝试从 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();

image 返回一个 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");

关于C#加载JPG文件,提取BitmapImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10330239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com