Azure的斑点和缩略图 [英] Azure blobs and thumbnails

查看:171
本文介绍了Azure的斑点和缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图像clear.jpg和thumbclear.jpg,第二个是我的缩略图
从第一个具有以下code创建:
我没有做任何调整大小尚未

 位图位图=新位图(File.InputStream);
  MemoryStream的ST =新的MemoryStream();
  尝试
  {
     bitmap.Save(ST,ImageFormat.Png);
     返回ST;
  }
  最后
  {
     bitmap.Dispose();
  }

所以后来我都上传图像至斑点,我得到他们的URI和复制/粘贴它们到
浏览器。
第一个
http://127.0.0.1:10000/devstoreaccount1/media/e1a987d1-c731-4e26-9e6c-d7a63b62f661/clear.png
工作正常,

但第二个<一href=\"http://127.0.0.1:10000/devstoreaccount1/media/b7ba6428-9db4-4282-8991-7a8198e7126f/thumbclear.png\" rel=\"nofollow\">http://127.0.0.1:10000/devstoreaccount1/media/b7ba6428-9db4-4282-8991-7a8198e7126f/thumbclear.png
给了我以下错误:

图片的http://...thumbclear.png无法显示,因为它包含错误

所以我supose它是与位图流。
任何帮助将AP preciated。

* *修改
在code我用它来保存BLOB

 公共静态CloudBlob SaveFileToBlob(MemoryStream的流串blobContainerName,字符串的文件名,扩展名字符串,字符串的contentType,INT档案大小)
        {
            如果(流!= NULL)
            {
                CloudBlobContainer _BlobContainer = SessionHelper.GetBlobContainer(blobContainerName);
                VAR的权限=新BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                _BlobContainer.SetPermissions(权限);                GUID blobid = Guid.NewGuid();
                变种斑点= _BlobContainer.GetBlobReference(blobid.ToString()+/+文件名);
                blob.UploadFromStream(流);                blob.Metadata [文件名] =文件名;
                blob.Metadata [扩展] =扩展;
                blob.Metadata [文件大小] = fileSize.ToString();
                blob.SetMetadata();                blob.Properties.ContentType的contentType =;
                blob.SetProperties();                返回Blob的;
            }
            其他
                返回null;
        }


解决方案

解决方案是上传到BLOB之前设置流位置为零。

  stream.Position = 0;
blob.UploadFromStream(流);

I have two images clear.jpg and thumbclear.jpg, the second one is a thumbnail I create from the first one with the following code: I am not doing any resize yet

  Bitmap bitmap = new Bitmap(File.InputStream);
  MemoryStream st = new MemoryStream();
  try
  {
     bitmap.Save(st, ImageFormat.Png);
     return st;
  }
  finally
  {
     bitmap.Dispose();
  }

so then I upload both Images to blobs and I get their URIs and copy/paste them to browser. The first one http://127.0.0.1:10000/devstoreaccount1/media/e1a987d1-c731-4e26-9e6c-d7a63b62f661/clear.png is working fine,

but the second one http://127.0.0.1:10000/devstoreaccount1/media/b7ba6428-9db4-4282-8991-7a8198e7126f/thumbclear.png gives me the following error:

The image "http://...thumbclear.png" cannot be displayed, because it contains errors.

So I supose it has something to do with the bitmap to stream. Any help will be appreciated.

**Edit The code I use to save the 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;
        }

解决方案

The solution was to set the stream position to zero before uploading to blob.

stream.Position = 0;
blob.UploadFromStream(stream);

这篇关于Azure的斑点和缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆