I am looking to export my chart to a memory strea, but I can not seem to get it to work. I have read through the forums and it seems like everyone is suggesting that I do it as shown below. If I run the proram like this, it tells me that I can not have a null value for my stream. Can someone please tell me what I am missing here in order to get the image into a memory stream?
Dim Stream1 As System.IO.MemoryStream = New System.IO.MemoryStream()
20: shippedpermthChart.Chart.Printer.Landscape = True
shippedpermthChart.Chart.Export.Image.PNG.Height = 450
shippedpermthChart.Chart.Export.Image.PNG.Width = 750
'shippedpermthChart.Chart.Export.Image.PNG.Save("\\10.49.32.235\WEBSHARED\MetricsTemp\ShppedPerMth" & I & ".png")
shippedpermthChart.Chart.Export.Image.PNG.Save(Stream1)
Saving to Memory Stream problem
Re: Saving to Memory Stream problem
Hello phil1995,
Ok. The problem is that you need define the type of image as you want to save, as explains in image save method.
So, using previous code your problem should be solved, if it doesn't solve, please let me know.
I hope will helps.
Thanks,
Ok. The problem is that you need define the type of image as you want to save, as explains in image save method.
Code: Select all
Private Sub button1_Click(sender As Object, e As EventArgs)
Dim stream As New System.IO.MemoryStream()
tChart1.Chart.Printer.Landscape = True
tChart1.Export.Image.PNG.Height = 450
tChart1.Export.Image.PNG.Width = 750
tChart1.Export.Image.PNG.Save("C:\tmp\teechart.png")
tChart1.Export.Image.PNG.Save(stream,"teechart1.png")
End Sub
I hope will helps.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Saving to Memory Stream problem
Thanks for that. I was trying to avoid having to save the file to a physical location such as c:\.....
I have found that the following method just keeps the file in memory and seems to work fine. For whatever reason, it has to be within a "Using" clause.
Using Stream3 As MemoryStream = New MemoryStream
TotalOrderBookChart.Chart.Printer.Landscape = True
TotalOrderBookChart.Chart.Export.Image.PNG.Height = 450
TotalOrderBookChart.Chart.Export.Image.PNG.Width = 750
TotalOrderBookChart.Chart.Export.Image.PNG.Save(Stream3)
Dim myimage3 As New System.Drawing.Bitmap(Stream3)
Dim Ximage3 As XImage
Ximage3 = Ximage3.FromGdiPlusImage(myimage3)
Dim mywidth3, myheight3 As Integer
mywidth3 = (Int32.Parse(Page3.Width) - Ximage3.PixelWidth) / 2
myheight3 = (Int32.Parse(Page3.Height) - Ximage3.PixelHeight) / 2
gsx3.DrawImage(Ximage3, mywidth3, myheight3, 750, 450)
gsx3.Dispose()
Stream3.Flush()
Stream3.Dispose()
Stream3.Close()
End Using
I have found that the following method just keeps the file in memory and seems to work fine. For whatever reason, it has to be within a "Using" clause.
Using Stream3 As MemoryStream = New MemoryStream
TotalOrderBookChart.Chart.Printer.Landscape = True
TotalOrderBookChart.Chart.Export.Image.PNG.Height = 450
TotalOrderBookChart.Chart.Export.Image.PNG.Width = 750
TotalOrderBookChart.Chart.Export.Image.PNG.Save(Stream3)
Dim myimage3 As New System.Drawing.Bitmap(Stream3)
Dim Ximage3 As XImage
Ximage3 = Ximage3.FromGdiPlusImage(myimage3)
Dim mywidth3, myheight3 As Integer
mywidth3 = (Int32.Parse(Page3.Width) - Ximage3.PixelWidth) / 2
myheight3 = (Int32.Parse(Page3.Height) - Ximage3.PixelHeight) / 2
gsx3.DrawImage(Ximage3, mywidth3, myheight3, 750, 450)
gsx3.Dispose()
Stream3.Flush()
Stream3.Dispose()
Stream3.Close()
End Using
Re: Saving to Memory Stream problem
Hello phil1995,
I am glad that you find a solution for your problem . On the other hand, when I have proposed my code so you use this line of code tChart1.Export.Image.PNG.Save(stream,"teechart1.png"); to save a image png in Memory Stream.
Thanks,
I am glad that you find a solution for your problem . On the other hand, when I have proposed my code so you use this line of code tChart1.Export.Image.PNG.Save(stream,"teechart1.png"); to save a image png in Memory Stream.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Saving to Memory Stream problem
Thanks, I guess I misunderstood what you were telling me. I read it to mean that both lines below were required to complete the command, whereas I was trying to avoid the first line of saving the file to a physical location on the drive. I assume from your comment, that the first line is not required to complete the second line. Is that correct?
tChart1.Export.Image.PNG.Save("C:\tmp\teechart.png")
tChart1.Export.Image.PNG.Save(stream,"teechart1.png")
tChart1.Export.Image.PNG.Save("C:\tmp\teechart.png")
tChart1.Export.Image.PNG.Save(stream,"teechart1.png")
Re: Saving to Memory Stream problem
Hello phil1995,
Yes, is correct. You only need the second line to save tChart as Memory stream.
Thanks,
Yes, is correct. You only need the second line to save tChart as Memory stream.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |