Looped output of images via 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 <img> html
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:

[Note, 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!

~Al
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top