Multiple images via one MemoryStream?

A

Alec MacLean

Hi,
I'm trying to write a set of charts (as bitmap objects) out to a memory
stream so that a variable number of charts can be displayed using just one
html <img> tag in a holder page. I have everything working except that only
one chart is ever displayed, no matter how many are actually created. The
vb codebehind is called by being placed as the source for an img tag in a
holder page. The holder page also provides a filter for the rendering code
in the form of a dropdownlist - the selected value of which is passed as a
param to the SQL sproc.

Here's the particular section of my code that is outputting the image:

[BEChart is of type BitMap]
<-snipped->
Dim memStream As New System.IO.MemoryStream

Try
' 'Write the chart images held in the array to the output stream
For iLoop = 0 To aryEnts.GetUpperBound(0)
If Not IsNothing(aryEnts(iLoop).BEChart) Then
'Add the current chart to the stream
aryEnts(iLoop).BEChart.Save(memStream,
System.Drawing.Imaging.ImageFormat.Png)
End If
Next
''Get beginning of stream...
memStream.Seek(0, IO.SeekOrigin.Begin)
''...and write it all out
memStream.WriteTo(Response.OutputStream)

Catch ex As Exception
strMsg = ex.Message.ToString
Finally
memStream.Close()
End Try

<-end->

Has anyone taken this approach before?

I wonder if the use of the single img tag on the holder page is forcing IE
only render one image (happens to be the last one generated in the loop).

I also wonder if the memStream is being overwritten instead of concatenated,
as the stream position value shown in the "locals" panel seems to jump
around and not always be at the end of the stream, which is where I would
have expected it to be...

E.g.
pass 1: capacity/length = 4706, position = 4706
pass 2: capacity/length = 4076, position = 2098
pass 3: capacity/length = 4076, position = 2062

Thanks for any help offered!
 
K

Kevin Spencer

Hi Alec,

Hard to say for sure what ALL of your problems are, but at least one of them
is that you are indeed overwriting the images in the memory stream. Another
is that you can't simply concatenate Bitmaps together. I can't tell from
your message whether you are using a separate ASPX page to generate the
image, but that is a necessity (an HTML document, which is what the img tag
is in, is a text file, and images must be requested separately by the
browser). And you should be sure that what you want to do is to combine
these images; the result may not be what you expect or desire. I identified
a couple of other potential issues you may be having, but I think you need
to re-evaluate your overall approach first. You're jumping through a lot of
hoops to avoid a little HTML (extra image tags) in your ASPX page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Alec MacLean said:
Hi,
I'm trying to write a set of charts (as bitmap objects) out to a memory
stream so that a variable number of charts can be displayed using just one
html <img> tag in a holder page. I have everything working except that only
one chart is ever displayed, no matter how many are actually created. The
vb codebehind is called by being placed as the source for an img tag in a
holder page. The holder page also provides a filter for the rendering code
in the form of a dropdownlist - the selected value of which is passed as a
param to the SQL sproc.

Here's the particular section of my code that is outputting the image:

[BEChart is of type BitMap]
<-snipped->
Dim memStream As New System.IO.MemoryStream

Try
' 'Write the chart images held in the array to the output stream
For iLoop = 0 To aryEnts.GetUpperBound(0)
If Not IsNothing(aryEnts(iLoop).BEChart) Then
'Add the current chart to the stream
aryEnts(iLoop).BEChart.Save(memStream,
System.Drawing.Imaging.ImageFormat.Png)
End If
Next
''Get beginning of stream...
memStream.Seek(0, IO.SeekOrigin.Begin)
''...and write it all out
memStream.WriteTo(Response.OutputStream)

Catch ex As Exception
strMsg = ex.Message.ToString
Finally
memStream.Close()
End Try

<-end->

Has anyone taken this approach before?

I wonder if the use of the single img tag on the holder page is forcing IE
only render one image (happens to be the last one generated in the loop).

I also wonder if the memStream is being overwritten instead of concatenated,
as the stream position value shown in the "locals" panel seems to jump
around and not always be at the end of the stream, which is where I would
have expected it to be...

E.g.
pass 1: capacity/length = 4706, position = 4706
pass 2: capacity/length = 4076, position = 2098
pass 3: capacity/length = 4076, position = 2062

Thanks for any help offered!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top