1

aspx ページに syncfusion chartwebcontrol があり、チャートをデータベースのバイナリ列に保存する必要があります。syncfuion コントロールのイメージをバイト形式にする方法がわかりません。

4

1 に答える 1

0

メソッドを使用してChartWebControlasを保存し、コンセプトを使用してこの画像をバイナリ データに変換し、このバイナリ データをデータベースに保存できます。クラスを使用して、チャート イメージをバイナリに変換できます。ImageSaveImageStreamFile 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);
}
于 2012-09-14T07:25:12.373 に答える