【问题标题】:Azure blob Storage is messing Image QualityAzure blob 存储正在破坏图像质量
【发布时间】:2015-10-06 18:41:39
【问题描述】:

我正在使用 Azure Blob 存储来添加图像。由于某种原因,我的图像质量以不良方式改变,导致我的功能不正确。

有人可以说明一下吗?如何避免?

CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename);
file.Position = 0;
stickerBlob.Properties.ContentType = "image/bmp";
stickerBlob.UploadFromStream(file);    //its just a Stream Object. 

代码共享。我也提到了内容类型。我也可以下载并查看图像,但没有任何 ContentType ,我的逻辑在该图像上也失败了。

【问题讨论】:

  • 你能详细描述一下这个问题吗?
  • 我正在使用将图像文件上传到 blob 存储,即将文件转换为流 uploadImageFromStream。当我从 blob 存储下载该文件时。在我添加 blob 存储部分之前,我的流程运行良好。我也可以下载并查看图像,但图像质量仍然受到影响。
  • 请分享您的代码。我猜在上传/下载过程中的某个地方丢失了一些字节,因为代码没有正确处理边界条件。我也发生过很多次。
  • 我真的怀疑 Azure 是否正在重新编码您的图像...当您创建一个小的可执行 repo 代码时,您会发现 无意中这样做了。

标签: azure azure-blob-storage


【解决方案1】:

将图像保存为 .png 格式会很好。您可能需要指定其他格式的压缩级别 (https://msdn.microsoft.com/en-us/library/bb882583(v=vs.110).aspx)

public bool UploadImage(Bitmap bitmap)
{
    bool success = false;
    try
    {
        CloudBlobContainer container = BlobClient.GetContainerReference("YourContainerName");
        CloudBlockBlob blob = container.GetBlockBlobReference("YourBlobReference");
        blob.Properties.ContentType = "image/png";
        byte[] file;
        using (MemoryStream stream = new MemoryStream())
        {
            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            file = stream.ToArray();
        }
        blob.UploadFromStream(new MemoryStream(file));
        success = true;

    }
    catch (Exception ex)
    {
        //Handle error here
    }
    return success;
}

【讨论】:

    猜你喜欢
    • 2019-07-28
    • 2017-10-18
    • 1970-01-01
    • 2019-04-03
    • 2017-10-27
    • 1970-01-01
    • 2020-10-08
    • 2018-07-11
    • 2017-01-27
    相关资源
    最近更新 更多