簡體   English   中英

MemoryStream 進入 MagicImage

[英]MemoryStream into MagicImage

我正在嘗試將 MemoryStream 存儲到 MagicImage 中,但是當我嘗試以 heic 格式上傳文件時,它仍然以 heic 格式上傳,但它應該以 jpeg 格式上傳。 所以我有點不明白我在哪里做錯了。 那么有人可以幫助我嗎?

                using (MemoryStream ms = new MemoryStream())
                {
                    create.PostedFile.InputStream.CopyTo(ms);
                    var data = ms.ToArray();


                    byte[] data1 = null;
                    using (var image = new MagickImage(data))
                    {
                        // Sets the output format to jpeg
                        image.Format = MagickFormat.Jpeg;

                        // Create byte array that contains a jpeg file
                        data1 = image.ToByteArray();
                    }

                    var file = new ClientFile
                    {
                        Data = data1, // here where it should store it in jpeg
                    };

雖然我從未使用過您編寫圖像的方式,但這是我在實現中使用的方式,並且它始終有效:

var image = new MagickImage(sourceStream);
var format = MagickFormat.Jpg;
var stream = new MemoryStream();
image.Write(stream, format);
stream.Position = 0;

編輯如果您不添加:

stream.Position = 0

發送 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 將不起作用,因為它將從當前 position 開始保存,該 position 位於 stream 的末尾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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