Saving to Memory Stream problem

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
phil1995
Newbie
Newbie
Posts: 31
Joined: Fri Dec 16, 2005 12:00 am
Location: Hattiesburg, Ms.
Contact:

Saving to Memory Stream problem

Post by phil1995 » Mon Oct 03, 2011 9:26 pm

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)

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving to Memory Stream problem

Post by Sandra » Tue Oct 04, 2011 2:25 pm

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.

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
So, using previous code your problem should be solved, if it doesn't solve, please let me know.
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
Image Image Image Image Image Image
Instructions - How to post in this forum

phil1995
Newbie
Newbie
Posts: 31
Joined: Fri Dec 16, 2005 12:00 am
Location: Hattiesburg, Ms.
Contact:

Re: Saving to Memory Stream problem

Post by phil1995 » Tue Oct 04, 2011 3:32 pm

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving to Memory Stream problem

Post by Sandra » Wed Oct 05, 2011 8:18 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

phil1995
Newbie
Newbie
Posts: 31
Joined: Fri Dec 16, 2005 12:00 am
Location: Hattiesburg, Ms.
Contact:

Re: Saving to Memory Stream problem

Post by phil1995 » Wed Oct 05, 2011 11:26 am

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")

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving to Memory Stream problem

Post by Sandra » Wed Oct 05, 2011 11:38 am

Hello phil1995,

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
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply