我使用Azure Blob Storage添加图片。我的图像质量由于某种原因以不良方式改变,这导致我的功能不正确。
有人可以对它进行一些说明。我怎么能避免?
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename);
file.Position = 0;
stickerBlob.Properties.ContentType = "image/bmp";
stickerBlob.UploadFromStream(file); //its just a Stream Object.
代码共享。我也提到了内容类型。我也可以下载并查看图像但没有任何ContentType,我的逻辑也失败了。
答案 0 :(得分:2)
以.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;
}