Error converting a byte data to image in a UWP application
Tried to get the stream from the data and converting that to image but Error!
The error is:
system.drawing is not supported on this platform
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
you will need to use 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. 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.