Azure blob 存储破坏了图像质量
Azure blob Storage is messing Image Quality
我正在使用 Azure Blob 存储添加图像。我的图像质量由于某种原因以不良方式改变,导致我的功能不正确。
谁能给它点灯。我该如何避免?
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename);
file.Position = 0;
stickerBlob.Properties.ContentType = "image/bmp";
stickerBlob.UploadFromStream(file); //its just a Stream Object.
代码共享。我还提到了内容类型。我也可以下载并查看图像,但没有任何 ContentType ,而且我的逻辑对该图像也失败了。
将图片保存为 .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;
}
我正在使用 Azure Blob 存储添加图像。我的图像质量由于某种原因以不良方式改变,导致我的功能不正确。
谁能给它点灯。我该如何避免?
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename);
file.Position = 0;
stickerBlob.Properties.ContentType = "image/bmp";
stickerBlob.UploadFromStream(file); //its just a Stream Object.
代码共享。我还提到了内容类型。我也可以下载并查看图像,但没有任何 ContentType ,而且我的逻辑对该图像也失败了。
将图片保存为 .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;
}