Last post Dec 19, 2006 07:45 AM by KowDot
Dec 15, 2006 10:58 PM|KowDot|LINK
Please could someone help?
Dim oBuilder As System.Text.StringBuilder = New System.Text.StringBuilder()
context.Response.Write("document.write('" + JavaReplace(oBuilder.ToString) + "');") 'JavaReplace simply swaps out characters.
This all works great but I need to insert images into the HTML. I can reference the images with:
Dim imageBytes As Byte()
Dim im As Image = Image.FromFile(FILENAME)
Dim stream As MemoryStream = New MemoryStream()
imageBytes = stream.GetBuffer()
But how do I send them to the client - I'm guessing I have to stream them, something like this:
'Send back image.
context.Response.ContentType = "image/gif"
context.Response.BufferOutput = False
context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length)
but I'm having no joy whatsoever, please could someone help, thanks
Dec 16, 2006 02:31 AM|DMW|LINK
Bitmap bmp = (Bitmap) Image.FromFile( FILENAME );
bmp.Save( context.Response.OutputStream, ImageFormat.xxx )
context.Response.ContentType = "image/xxx"
where xxx is gif, jpg, etc.
Bearing in mind that saving an image as a GIF in GDI+ yields (typically) very poor results, because of its choice of a standard palette. You might want to check out MSDN, which has an article on this. I can't remember the URL at the moment, and I have to
dash, but a quick Google search for GIF, GDI+, MSDN and octree should get you there.
Dec 16, 2006 02:04 PM|KowDot|LINK
Thanks DMW I'll attempt to have another go tonight. I'll let you know how I get on...
I'm looking to use this technique to serve ads from my website.
Dec 17, 2006 01:22 PM|KowDot|LINK
Dec 17, 2006 07:30 PM|DMW|LINK
You should be using <img src="..." /> to display the image.
Dec 17, 2006 08:31 PM|KowDot|LINK
The images are stored on my site and not the clients! How do I reference the images on my site to appear on the clients!
Do I just use for example: <img src="http://mysite.com/myimages/image1.gif" ... etc. ?
Dec 17, 2006 09:59 PM|DMW|LINK
If the images have known addresses, then just put <img src="url of image" /> on the page. If you want to do something programmatically, then write a handler
that returns images and then put <img src="url of handler" /> on the page. If you want to make it appear that the images are generated on the client site, not yours, then write a handler that the client installs that requests the image data
If you want to simplify their page design, write a server-side control that emits the HTML containing the call to the handler (e.g. wraps <img src="url of handler" />), but that seems a little pointless unless there is more HTML to be generated (e.g. you
want the <img> tag to appear inside a table, or come with client-side script for some other purpose).
and that simply wouldn't be a sane idea.
Dec 18, 2006 08:00 AM|KowDot|LINK
Dec 19, 2006 07:45 AM|KowDot|LINK
Thanks Dave, Managed to get it all working quite easily last night. It's amazing what can be done when you have the correct knowledge. Thanks again for all your help, you have saved me hours and hours :)