Azure blob存储正在破坏图像质量
我正在使用Azure Blob存储添加图像。由于某种原因,我的图像质量被以不好的方式更改,这导致我的功能不正确 有人能给它点光吗。我怎样才能避免Azure blob存储正在破坏图像质量,azure,azure-storage-blobs,azure-blob-storage,Azure,Azure Storage Blobs,Azure Blob Storage,我正在使用Azure Blob存储添加图像。由于某种原因,我的图像质量被以不好的方式更改,这导致我的功能不正确 有人能给它点光吗。我怎样才能避免 CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename); file.Position = 0; stickerBlob.Properties.ContentType = "image/bmp"; stickerBlob.UploadFromStream(file);
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(filename);
file.Position = 0;
stickerBlob.Properties.ContentType = "image/bmp";
stickerBlob.UploadFromStream(file); //its just a Stream Object.
代码共享。我还提到了内容类型。我也可以下载并查看图像,但是没有任何ContentType,我的逻辑在该图像上也失败了 以.png格式保存图像会很好。您可能需要为其他格式指定压缩级别()
您能更详细地描述一下这个问题吗?我正在使用将文件转换为流uploadImageFromStream将图像文件上载到blob存储。当我从blob存储下载该文件时。在添加blob存储部分之前,我的流程运行得很好。我可以下载并查看图像,但图像质量仍然受到影响。请共享您的代码。我猜在上传/下载过程中,某些字节丢失了,因为代码没有正确处理边界条件。我也经历过很多次。我真的怀疑Azure是否在重新编码你的图像。。。当您创建一个小的、可执行的repo代码时,您会发现您是在无意中这样做的。
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;
}