Memorystream looks like empty

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
Junhui
Posts: 8
Joined: Wed Jan 18, 2012 10:22 am

Memorystream looks like empty

Post by Junhui » Fri Jan 27, 2012 9:29 am

Hello, I have a question for this issue...

I opened image file on AnnotationViewer and draw some annotations, and saved that.
Saving to image, it works. But saving to memorystream, it doesn't work.
Here are codes below...

Code: Select all

private void btnSave_Click(object sender, EventArgs e)
{
   MemoryStream mstream = new MemoryStream();
   JpegEncoder encoder = new JpegEncoder();

   annotationViewer1.Image.SaveAnnotations = true;
   annotationViewer1.Image.Save(mstream, encoder);
   annotationViewer1.Image.Save(@"C:\TEST\tmpImg.jpg", encoder);

   FileStream fstream = new FileStream(@"C:\TEST\tmpImg.jpg", FileMode.Open);
   StreamReader sr = new StreamReader(fstream);
   string tmpImg = sr.ReadToEnd();

   StreamReader sr2 = new StreamReader(mstream);
   string tmpImg2 = sr2.ReadToEnd();
            
   //save annotationed image to DB
   SavePictChart(tmpImg);
}
At sr(streamreader which reads saved file), tmpImg is not null, but at sr2(streamreader which reads memorystream), it doesn't have value.
I have to insert image with querystring to sybase database, so I need Memorystream.
Thank you for your reading., FileMode

Alex
Site Admin
Posts: 1443
Joined: Thu Jul 10, 2008 2:21 pm

Re: Memorystream looks like empty

Post by Alex » Fri Jan 27, 2012 11:31 am

Hello,

You need to move the position in the memory stream to the beginning of the stream before reading data from the stream:

Code: Select all

mstream.Position = 0;
StreamReader sr2 = new StreamReader(mstream);
string tmpImg2 = sr2.ReadToEnd();
Best regards, Alexander

Junhui
Posts: 8
Joined: Wed Jan 18, 2012 10:22 am

Re: Memorystream looks like empty

Post by Junhui » Tue Jan 31, 2012 8:21 am

It works well, thank you for your advice. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests