2011-10-21 48 views

回答

0

您可以通過使用SaveImage方法保存ChartWebControlImage,那麼這個圖像轉換爲使用Stream概念二進制數據和數據庫保存這個二進制數據。您可以使用File Stream類將圖表圖像轉換爲二進制。

請參考下面的代碼片段

[C#]

this.ChartWebControl1.SaveImage(Server.MapPath("Chart.png")); 
byte[] buffer = ImageToBinary(Server.MapPath("Chart.png")); 
//Insert the above buffer data to db for chart image binary data 
-------------------------------- 
public static byte[] ImageToBinary(string imagePath) 
{ 
    FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read); 
    byte[] buffer = new byte[fileStream.Length]; 
    fileStream.Read(buffer, 0, (int)fileStream.Length); 
    fileStream.Close(); 
    return buffer; 
} 

可以二進制數據轉換回圖像,請參考下面的代碼片段。

[C#]

public static Image BinaryToImage(System.Data.Linq.Binary binaryData) 
{ 
    if (binaryData == null) return null; 
    byte[] buffer = binaryData.ToArray(); 
    MemoryStream memStream = new MemoryStream(); 
    memStream.Write(buffer, 0, buffer.Length); 
    return Image.FromStream(memStream); 
} 
相關問題