[英]System.Drawing error on Save image from byte data
在 UWP 应用程序中将字节数据转换为图像时出错
试图从数据中获取 stream 并将其转换为图像,但错误!
错误是:
此平台不支持 system.drawing
videoParser.Initialize(delegate (byte[] data)
{
using (MemoryStream mStream = new MemoryStream(data))
{
System.Drawing.Image img = System.Drawing.Image.FromStream(mStream);
img.Save(@"D:/img.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
return DJISDKManager.Instance.VideoFeeder.ParseAssitantDecodingInfo(0, data);
});
我想将图像保存为 jpeg 格式
您将需要使用 IFormFile
private string SaveImage(Guid AdID, IFormFile Photo)
{
if (Photo != null)
{
string uploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "AdsImages");
string UniqueFileName = AdID.ToString() + "_" + Photo.FileName;
string FilePath = Path.Combine(uploadFolder, UniqueFileName);
Photo.CopyTo(new FileStream(FilePath, FileMode.Create));
return UniqueFileName;
}
else
{
return null;
}
}
从@Amy 共享的链接看来,System.Drawing 似乎不适用于通用 Windows 应用程序。 如果您只想从数据中保存图像,您可以先创建一个文件,然后将字节写入其中。
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"D:\");
StorageFile file = await folder.CreateFileAsync("img.jpg", CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBytesAsync(file, data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.