[英]System.Drawing error on Save image from byte data
Error converting a byte data to image in a UWP application在 UWP 应用程序中将字节数据转换为图像时出错
Tried to get the stream from the data and converting that to image but Error!试图从数据中获取 stream 并将其转换为图像,但错误!
The error is:错误是:
system.drawing is not supported on this platform此平台不支持 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);
});
I want to save the image in jpeg format我想将图像保存为 jpeg 格式
you will need to use IFormFile您将需要使用 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;
}
}
From the link @Amy shared, it seems that System.Drawing is not available for universal Windows Apps.从@Amy 共享的链接看来,System.Drawing 似乎不适用于通用 Windows 应用程序。 If you only want to save the image from the data, you can first create a file and then write the bytes in it.如果您只想从数据中保存图像,您可以先创建一个文件,然后将字节写入其中。
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.