|
Saving chart.png in SQL Server database |
Posted by Hans Peter, Denmark on Feb-12-2010 17:03 |
|
Hello!
I have a well working app including ChartDir charts.
Normally I use this code for saving images in SQL Server:
[code]
Public Sub SaveImage()
Dim connectionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
connectionString = ConfigurationManager.ConnectionStrings("IsoPlusConnectionStringDrift").ConnectionString
connection = New SqlConnection(connectionString)
Dim command As New SqlCommand("UPDATE Nomogram SET Img1 = @Picture WHERE bID = 135", connection)
Using picture As Image = Image.FromFile("C:\\td4.png")
Using stream As New IO.MemoryStream
picture.Save(stream, Imaging.ImageFormat.Png)
command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = stream.GetBuffer()
End Using
End Using
connection.Open()
command.ExecuteNonQuery()
connection.Close()
End Sub
[/code]
How do I do that for the chart that I generate?
WebChartViewer1.Image = c.makeWebImage(Chart.PNG) which include all the data, that I have programmed to the image?
Can I convert the ChartDirector.WebImage to a System.Drwaing.Image? |
Re: Saving chart.png in SQL Server database |
Posted by Peter Kwan on Feb-12-2010 17:18 |
|
Hi Hans Peter, Denmark,
You may not need to have the System.Drawing.Image at all.
I have not tried myself, but I guess you can use:
command.Parameters.Add("@Picture", SqlDbType.VarBinary).Value = c.makeChart2(Chart.PNG)
The BaseChart.makeChart2 creates the chart as a byte array representing the PNG image of the chart. You should be able to save it to a database.
If you want to have the System.Drawing.Image, you can use BaseChart.makeImage (instead of BaseChart.makeWebImage).
Hope this can help.
Regards
Peter Kwan |
Re: Saving chart.png in SQL Server database |
Posted by Steve on Apr-06-2013 06:27 |
|
I am doing something similar to this. I was able to save the byte array to the database with mc.makeChart2(Chart.PNG).
But, how do I recreate that image back to a WebImage?
I can convert to a System.Drawing.Image using the System.Drawing.Image.FromStream function. But is there a way to convert to a ChartDirector.WebImage?
Thanks |
Re: Saving chart.png in SQL Server database |
Posted by Peter Kwan on Apr-09-2013 04:18 |
|
Hi Steve,
The WebImage basically is a normal image (the same image you created using makeChart2), plus some additional information used to support drag to zoom/scroll and track cursor interactions.
If what you need is just to display the chart, then you are recreate the WebImage by:
XYChart temp = new XYChart(1, 1);
temp.makeChart3().loadPNG(new System.IO.MemoryStream(myByteArray));
WebImage output = temp.makeWebImage();
The above will be the same as the original chart, but without the information required to support drag to zoom/scroll and track cursor interactions. (Such information includes the position and size of the plot area, ...). You can still use image maps for tooltips and clickable hot spots.
Hope this can help.
Regards
Peter Kwan |
|