【问题标题】:Upload image with transparent background to azure blob displays the image with black background将具有透明背景的图像上传到 azure blob 显示具有黑色背景的图像
【发布时间】:2021-04-28 09:46:58
【问题描述】:
using (var memoryStream = new MemoryStream())
            {
                await image.CopyToAsync(memoryStream);
                using (var img = System.Drawing.Image.FromStream(memoryStream))
                {

                    var bytesImage = Utilities.ImageToByteArray(img, ImageFormat.Jpeg);

                    using (MemoryStream memstr = new MemoryStream(bytesImage))
                    {
                        await blob.UploadFromStreamAsync(memstr);
                    }

                }
            }

上面的代码是用来上传文件到blob存储的,图片就是这样透明的

上传后,结果是这样的黑色背景

【问题讨论】:

  • 方法Utilities.ImageToByteArray是做什么的?原图格式是什么?
  • 好吧,您将图片转换为Jpg - 一种不支持透明度的格式。除了选择另一种格式之外,您无能为力。
  • @FranzGleichmann 感谢您的帮助,我将格式更改为我尝试上传“在我的情况下为 png”的图像格式,它可以正常工作。
  • 你能把它作为答案发布吗?

标签: c# asp.net-mvc azure


【解决方案1】:

请关注@Franz Gleichmann 回答, “嗯,你把你的图片转换成 Jpg - 一种不支持透明度的格式。在那里你什么都做不了,除了选择另一种格式”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多