gpt4 book ai didi

c# - 将图像数据转换为流

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:41 25 4
gpt4 key购买 nike

我正在尝试将图像数据转换为流以获取 ExifInfo/元数据

 MediaLibrary library = new MediaLibrary();
Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]);

photoFromLibrary.GetImage(); 仅返回 ImageData

我需要它在我的方法中使用

public static void GetMetaData(Stream photo)
{
ExifLib.JpegInfo info = ExifLib.ExifReader.ReadJpeg(photo);
var img = new BitmapImage();
img.SetSource(photo);
App.MainViewModel.MetaDate = ReadExif(info);
}

ExifLib.ExifReader.ReadJpeg(photo); 需要一个流

所以我从 photoFromLibrary.GetImage(); 得到的是 ImageData,但我需要一个 stream。那么如何将 ImageData 转换为 stream 呢?

最佳答案

       I hope your are looking for this result.            


var wb = new WriteableBitmap(ContentPanel, new TranslateTransform());

using (var mediaLibrary = new MediaLibrary())
{
using (var stream = new MemoryStream())
{
var fileName = string.Format("{0}.jpg", DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"));
wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
var picture = mediaLibrary.SavePicture(fileName, stream);
}
}

关于c# - 将图像数据转换为流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27442142/

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