簡體   English   中英

System.Drawing 錯誤從字節數據保存圖像

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM