1
私はaspxページにsyncfusion chartwebcontrolを持っており、バイナリ列のデータベースにグラフを保存する必要があります。私はsyncfuionコントロールの画像をバイト形式にする方法がわかりません。DBに保存するためのsyncfusion chartwebcontrolのバイナリデータを取得するには?
私はaspxページにsyncfusion chartwebcontrolを持っており、バイナリ列のデータベースにグラフを保存する必要があります。私はsyncfuionコントロールの画像をバイト形式にする方法がわかりません。DBに保存するためのsyncfusion chartwebcontrolのバイナリデータを取得するには?
SaveImage
メソッドを使用してImage
として保存し、Stream
コンセプトを使用してこのイメージをバイナリデータに変換し、このバイナリデータをデータベースに保存することができます。 File Stream
クラスを使用して、チャートイメージをバイナリに変換することができます。
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#の]を参照してください、コードスニペットの下に参照してください。
[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);
}