Need Help with Thumbnail Gallery in Panel


David Elliott

I am creating a control to display GIF/JPEG images for my website. The control
has a Panel to hold the images.

I would like to perform the following.
1) store the original on disk and create a thumbnail on the fly.
2) thumbnail will be 20% of the original size.
3) the panel will hold all the images of a specific directory

Using System.Drawing.Image, I can satisfy number 1 and 2, but how would I
output the info to the panel?

Is this the best way to do it or is there an alternative?


(e-mail address removed)



Rick Strahl [MVP]

Hi David,

AS you've found out the GDI+ stuff is pretty trivial.

But updating the data may not be. There are a couple of ways to do what you
need. I have a photoalbum app that basically does what you do and it uses
both approaches from time to time.

First and probably best is to gen the pictures once and store them with the
real images. Give them some sort of prefix and then read that prefix into
your panel as a regular image link. This is most efficient because you only
gen the images once when you upload or change them. You either update them
as changes are made or re-gen the whole batch (in case some other means of
uploading or installing was used such as FTP).

If you can't have images sitting around then you can stream them directly
back one at a time. For your image link do something like:

<img src="ImageShrinker.aspx?Image=ImageName&Path=xxxx">

Then create the ImageShrinker page to actually shrink one image at a time
and return it as needed when the page loads and the img tags cause each to

To stream an image just do this:

Response.ContentType = "image/gif"; (or whatever)
Bitmap.Save(Response.OutputStream,ImageFormat.Gif); (or whatever)

Oh if your images are really small (in download size) to start with you can
maybe even just embed them with an image size. The browser will auto-resize
without any furhter work, but it will still download the whole image. Main
issue with that is that you have little control how the image gets resized -
not a problem if they're all the same size, but otherwise the image gets

Hope this helps,

+++ Rick ---


Rick Strahl
West Wind Technologies