473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Multiple images via one MemoryStream?

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!
--
Alec MacLean

Nov 18 '05 #1
1 2851
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" <al**********@copeohs.com.NO_SPAM> wrote in message
news:#r**************@TK2MSFTNGP12.phx.gbl...
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!
--
Alec MacLean

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Detlef Hüttenbach | last post by:
Whereas loading tiffs and pngs from file into an Image WebControl work, the images aren't shown when loaded from streams: In a WebForm, the image's property "ImageUrl" is set to a handler, and...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
9
by: charliewest | last post by:
Hello - I have images saved in my SQL SERVER 2000 database. Using ASP.NET (C#) is there any way to temporarily save an image to a session object, and after running some other operations, later...
8
by: Bob | last post by:
I'm looking for an example of how to extract images from an Access 97 blob into an asp datagrid. Anybody have examples?
4
by: Lindsey Howell | last post by:
Hello, I've encountered a problem when trying to display BLOB images from a SQL database using VB.NET. This is the code which generates the error: Dim mySqlConnection As SqlConnection = New...
3
by: Alan | last post by:
Hi, I'm converting a database application from Access 97 to C#/SQL Server. Old database contains some images in OLE fields. I've figured out that there's OLE header preceeding actual image data...
5
by: Sameer Gupta | last post by:
what are options for opening / handling tiff files in .Net framework ? which is the best library, namespace ? Please help Regards Sameer Gupta C# Designer & Developer Siemens UK
1
by: san123456789 | last post by:
Hi, Im using a MS SQL server to store images... Im creating a windows form application using C#. I need to store and retrieve images from the database. This is my code to store images: ...
2
by: Marco Pais | last post by:
Hi there. I'm developing a small application that uses Web Services to access database and store data. At some point, I store some images, by inserting the absolute image path into a varchar...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.