2012-04-20 12 views
0

以下のルーチンのように、いくつかの環境では特定のURL(例:http://covers.oreilly.com/images/0636920022886/bkt.gif)では動作しますが、Azureでは失敗します。次の例外:Http範囲リクエストによるGIFディメンションの高速検出

System.ArgumentException:パラメータが無効です。全ての場合において System.Drawing.Image.FromStreamを(ストリームstream)

で System.Drawing.Image.FromStreamを(ストリームstream、ブール useEmbeddedColorManagement、ブールvalidateImageData)で、quetionにアセンブリがシステムです。 Drawing、Version = 4.0.0.0、Culture =ニュートラル、PublicKeyToken = b03f5f7f11d50a3aだから、受信したデータは何とかAzureで違うと仮定しています。

public static DimensionResult Is404(string url) 
    { 
     DimensionResult result = null; 

     HttpWebRequest request = Http.PrepareGetRequest(new Uri(url), false, false, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); 
     request.Timeout = 2500; 
     request.Method = "GET"; 
     request.AddRange(0, 2048); 
     request.KeepAlive = false; 
     request.AllowAutoRedirect = true; 

     try 
     { 
      result = new DimensionResult(); 

      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
      { 
       result.ContentEncoding = response.ContentEncoding; 
       result.Url = response.ResponseUri.ToString(); 
       result.Is404 = (response.StatusCode != HttpStatusCode.PartialContent && response.StatusCode != HttpStatusCode.OK) || System.Text.RegularExpressions.Regex.IsMatch(response.ContentType, "text|html", System.Text.RegularExpressions.RegexOptions.IgnoreCase); 

       if (!result.Is404) 
         using (System.Drawing.Image image = System.Drawing.Image.FromStream(response.GetResponseStream())) 
         { 
          result.Width = image.Width; 
          result.Height = image.Height; 
         } 
      } 
     } 
     catch (Exception ex) 
     { 
      result.Exception = ex; 
      result.Is404 = true; 
     } 

     return result; 
    } 

要求されたバイト数に焦点を当てて(これは簡易版である)が、サーバーからサーバーへの差分の応答を説明することができる.NETのネットワークスタックでどのような設定にしないでください?

どちらの場合も、私がこれまでのレスポンスヘッダを記録してきたし、彼らは同じだ、何のネットワークがまだトレースしません:

日:金、2012年4月20日11時47分05秒 GMT、サーバー:Apache、Accept-Ranges:バイト、Last-Modified:Fri、24 Feb 2012 17:21:00 GMT、Content-Range:バイト 0-2048/3556、Content-Length:2049、Content-Type:image/GIF、のCache-Control:最大エージング= 2592000は、有効期限:日、 2012年5月20日午前11時47分05秒GMT、接続:閉じる

更新: 私は両方の環境で受信したバイトを記録しましたが、それらは同じになります!同じ応答ヘッダー、同じ応答長さ、同じ応答内容、同じアセンブリ、異なる動作。

答えて

0

http://en.wikipedia.org/wiki/Graphics_Interchange_Formatによると、gifファイルは、文字「GIF87a」または「GIF89a」で始まり、その後に幅と高さが続きます。したがって、幅/高さの情報だけが必要な場合は、バイト6-9を読むことができます。 GDI +(System.Drawing.dll)は必要ありません。私の経験から、サーバー環境、特にWindows AzureでSystem.Drawing.dllを使用すると、予期しない結果が生じる可能性があります。高度なビットマップ処理が必要な場合は、WICまたはWPF(WICを使用します)を使用することができます。

最高のお礼、

Ming Xu。

関連する問題