[英]Azure blobs and thumbnails
我有兩張圖片clear.jpg和thumbclear.jpg,第二張是我用第一張圖片用以下代碼創建的縮略圖: 我尚未進行任何調整大小
Bitmap bitmap = new Bitmap(File.InputStream);
MemoryStream st = new MemoryStream();
try
{
bitmap.Save(st, ImageFormat.Png);
return st;
}
finally
{
bitmap.Dispose();
}
因此,我將兩個圖片都上傳到Blob,然后獲取了它們的URI,然后將其復制/粘貼到瀏覽器中。 第一個http://127.0.0.1:10000/devstoreaccount1/media/e1a987d1-c731-4e26-9e6c-d7a63b62f661/clear.png工作正常,
但是第二個http://127.0.0.1:10000/devstoreaccount1/media/b7ba6428-9db4-4282-8991-7a8198e7126f/thumbclear.png給我以下錯誤:
無法顯示圖像“ http://...thumbclear.png”,因為其中包含錯誤。
所以我認為這與要傳輸的位圖有關。 任何幫助將不勝感激。
* *編輯我用來保存Blob的代碼
public static CloudBlob SaveFileToBlob(MemoryStream stream, string blobContainerName, string filename, string extension, string contentType, int fileSize)
{
if (stream != null)
{
CloudBlobContainer _BlobContainer = SessionHelper.GetBlobContainer(blobContainerName);
var permissions = new BlobContainerPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
_BlobContainer.SetPermissions(permissions);
Guid blobid = Guid.NewGuid();
var blob = _BlobContainer.GetBlobReference(blobid.ToString() + "/" + filename);
blob.UploadFromStream(stream);
blob.Metadata["FileName"] = filename;
blob.Metadata["Extension"] = extension;
blob.Metadata["FileSize"] = fileSize.ToString();
blob.SetMetadata();
blob.Properties.ContentType = contentType;
blob.SetProperties();
return blob;
}
else
return null;
}
解決方案是在上傳到Blob之前將流位置設置為零。
stream.Position = 0;
blob.UploadFromStream(stream);
對於第一個樣本:
Bitmap bitmap = new Bitmap(File.InputStream); MemoryStream st = new MemoryStream(); try { bitmap.Save(st, ImageFormat.Png); //worked for me Response.ContentType = "image/png"; st.WriteTo(Response.OutputStream); //-- } finally { bitmap.Dispose(); }
而且,我今天發現
Function Index() As FileContentResult Dim Resim = New WebClient().DownloadData("https://dosyalar.blob.core.windows.net/dosya/kartalisveris.gif") Return New FileContentResult(Resim, "image/png") '* With {.FileDownloadName = "Höbölö"} End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.