2009-12-01 29 views
1

將映像數據類型轉換爲sybase中的字節數組? 我應用Web服務來獲取sybase中的數據集(圖像數據類型)。 我使用byte []來返回Web服務。 (ASP.NET C#) 但是有一個圖像失真問題(當我在圖像中的zoon,有些點被錯過)。然後我使用「response.binarywrite(byte [])」來顯示圖像。 我不知道爲什麼 有誰知道sybase中的圖像數據類型可以傳輸到字節數組?關於Sybase映像

Original Image

Distortion Image

系統:

1的Sybase

Sybase db: 11.9.2 

    Adaptive server enterprise 12.5.1 

    Sybase.Data.AseClient:1.0.152.0 

2 ASP.NET C#(Visual Studio 2008中)

3 IE6

回答

3

最後,我找到了anwser。 這個問題的原因是在Sybase中訪問圖像大小的限制。當圖像大小高於37k字節時,輸出仍爲37K。因此,我在這一步錯過了一些字節。解決方案是您需要設置參數來檢索所有數據。 的部分代碼顯示如下:

[WebMethod] 
    public byte[] Image(string c, string r) 
    { 
     //check input .. 
     ConnectionDatabase connbaseloc = new ConnectionDatabase(); 
     AseConnection conn1 = null; 
     AseCommand cmd1 = null; 
     string sqlstr1 = ""; 
     AseDataReader reader = null; 
     byte[] Imagebytes = null; 
     try 
     { 
      using (conn1 = connbaseloc.Odbcconn_xxx()) 
      { 
       string setTextCmd = " SET TEXTSIZE 130000"; //set parameter 
       cmd1 = new AseCommand(setTextCmd, conn1); 
       cmd1.ExecuteNonQuery(); 
       sqlstr1 = "select ...."; 
       cmd1 = new AseCommand(sqlstr1, conn1); 
       cmd1.CommandText = sqlstr1; 
       reader = cmd1.ExecuteReader(); 
       while (reader.Read()) 
       { 
        Imagebytes = (byte[])reader["Image"]; 
       } 
      } 
     } 
     catch (Exception e) 
     { 
      //do something 
     } 
     finally 
     { 
      if (conn1 != null) conn1.Close(); 
     } 

     return Imagebytes; 
    } 

參數值取決於圖像的最大尺寸。