Add a Bitmap ???

R

Robert

I need to add a dynamical!! generated bitmap to an image
button! What is the way to do it? The ImageButton offers
only the URL property. But this are physical file paths.

Dim new_bitmap As Bitmap = New Bitmap(850, 200)

Dim image_button As New System.Web.UI.WebControls.ImageButton

Thanks a lot

Rob
 
D

Daniel Bass

The problem you have is that your working in the server side's memory... and
so the image you're creating and using is, the server's buffer. When the
request from the client to the server is made to pass it a picture, it needs
to be a file that's requested, or the server won't know how to send it, and
the client won't know how to receive it and show it.

The only way you can do this is to first stream out the buffer, (i.e, save
the bitmap to disk), then take that URL you've just saved the file too and
pass that to the image button's URL.
I'd suggest using something like in the ASP page...

<A HREF="somefolder/somefile"><IMG BORDER=no ID=myImage
SRC="images/myTempPick.jpg"></A>

then when you've gotten the bitmap and saved it, something like... (aspx.vb
file)

dim ClientScript as String = ""
ClientScript += "<SCRIPT language=javascript>" & vbNewLine
ClientScript += " document.all.myImage.src = " & stringImageURL &
vbNewLine ' where stringImageURL is a string containing your image
location you've saved out
ClientScript += "</SCRIPT>
RegisterStartupScript( "ImageChange", ClientScript )

This code then writes the client side script to change your image URL from
the TempPick to whatever pic you now want. Note that I used HTML's standard
<IMG> rather than the <ASP:...>, I haven't played much with the ASP.net
controls in this way so am not sure what they'll do, try it!

hope that helps, and works!

Dan.
 
K

Kevin Spencer

You don't want a Bitmap. You want an image format that IS supported by
browsers, such as JPG or GIF. What you need to do is to create an ASPX page
that uses Response.BinaryWrite() to write the binary image to the Response.
This ASPX page must also set the ContentType to "image/jpg" or "image/gif"
to inform the browser that it is not an ASPX page that is being returned,
but an image. Your image button can then use the URL of the ASPX page as the
URL to the image.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Some things just happen.
Everything else occurs.
 
K

Kenn Ghannon

The May/June 2003 issue of CoDe (component developer magazine) had some
great articles on doing things of this nature. Basically, you need to use
the System.Drawing and System.Drawing.Imaging libraries. Use the source of
your image as an aspx page with a Response.ContentType = "image/jpeg" or
"image/gif" etc. I use something like this in a few of my pages <img
src="paint.aspx"> to create some dynamic images.

I don't want to violate copyright laws by repeating the source code that's
in there,
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top