【问题标题】:How to get binary data of syncfusion chartwebcontrol to save to DB?如何获取syncfusion chartwebcontrol的二进制数据保存到数据库?
【发布时间】:2011-10-21 19:15:04
【问题描述】:

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

【问题讨论】:

    标签: asp.net syncfusion


    【解决方案1】:

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

    请参考下面的代码sn-p

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

    您可以将二进制数据转换回图像,请参考下面的代码sn-p。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多