System.Drawing.Image.FromStream无效参数

时间:2013-05-14 15:07:32

标签: c# winforms

我试图从数据库中获取blob,但有时我收到错误"无效参数"

在这一行

System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);

这是我的代码:

public partial class showblob : System.Web.UI.Page
{

     private System.Drawing.Image.GetThumbnailImageAbort delegateabort;
     protected void Page_Load(object sender, EventArgs e)
     {
         // Get a handle on account, create a blob service client and get container proxy
         var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
         account.CreateCloudTableClient().CreateTableIfNotExist("tablename");
         var client = account.CreateCloudBlobClient();
         CloudBlobContainer container = client.GetContainerReference("tablename");
         string id = Request["id"].ToString();

         // Retrieve reference to a blob named "myblob"
         CloudBlob blob = container.GetBlobReference(id);
         BlobStream blobstream = blob.OpenRead();

         if (Request["imgvd"] == "0")
         {
             Response.ContentType = "image/jpeg";
             System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);

             if (Request["thumb"] != null)
                 objimg = objimg.GetThumbnailImage(140, 210, delegateabort, System.IntPtr.Zero);

             objimg.Save(Response.OutputStream, ImageFormat.Jpeg);
         }

并保存图像,因为我已经使用此方法添加:

if (fileFoto.HasFile)

     try
     {
         CloudBlobClient blobClient = account.CreateCloudBlobClient();
         // Retrieve a reference to a container 
         CloudBlobContainer container = blobClient.GetContainerReference("tablename");
         // Create the container if it doesn't already exist
         container.CreateIfNotExist();
         CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());               
         blob.UploadFromStream(fileFoto.PostedFile.InputStream);
     }

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。问题是我将引用设置为

CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());

当我上传照片并使用

拍摄时
CloudBlob blob = container.GetBlobReference(ViewState["id"].ToString());