Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何获取syncfusion chartwebcontrol的二进制数据以保存到DB?_Asp.net_Syncfusion - Fatal编程技术网

Asp.net 如何获取syncfusion chartwebcontrol的二进制数据以保存到DB?

Asp.net 如何获取syncfusion chartwebcontrol的二进制数据以保存到DB?,asp.net,syncfusion,Asp.net,Syncfusion,我的aspx页面中有一个syncfusion chartwebcontrol,我需要将图表以二进制列的形式保存到数据库中。我不知道如何将同步控件的图像转换为字节形式。您可以使用SaveImage方法将ChartWebControl保存为image,然后使用Stream概念将此图像转换为二进制数据,并将此二进制数据保存在数据库中。您可以使用文件流类将图表图像转换为二进制 请参考下面的代码片段 [C#] 您可以将二进制数据转换回图像,请参阅下面的代码段 [C#] this.ChartWebContr

我的aspx页面中有一个syncfusion chartwebcontrol,我需要将图表以二进制列的形式保存到数据库中。我不知道如何将同步控件的图像转换为字节形式。

您可以使用
SaveImage
方法将
ChartWebControl
保存为
image
,然后使用
Stream
概念将此图像转换为二进制数据,并将此二进制数据保存在数据库中。您可以使用
文件流
类将图表图像转换为二进制

请参考下面的代码片段

[C#]

您可以将二进制数据转换回图像,请参阅下面的代码段

[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;
}
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);
}