Thursday, October 28, 2004

Doh!

Don't you hate it when you do something so stoopid it makes you want to cry? That happened to me just this morning. Bugger.

Over the past couple of days I've been writing just a very quick easy app to batch resize a folderful of images. I wanted to get a bunch of pictures from a party (it was my birthday Saturday. Woo and Yay) and resize them to put online somewhere. SImple, I know. Yes, I could have donme them by hand. Yes, I could have downloaded one of a million free utilities to do the same thing, but hey, where's the fun in that?

Originally the plan was to do it this way:

  1. Load the image
  2. Create a new image (in GDI+) from the original image's GetThumbNailImage method
  3. Save that image
Simple huh? It's something I've done a few times for creating thumbnail images on the fly.

Turns out (and I didn't know this before) that if the image file already has a thumbnail associated to it, it just takes that image and resizes, rather than taking the original and resizing it. As a result, half of the images that were produced were horrible pixellated crap. Not good. So I spent a few hours trying some other stuff, looking for resize methods in all of the GDI+ objects, and a whole bunch of other stuff. I even toyed with writing my own resizing algorithm to do the job I wanted. I didn't go down that route, though.

No. The route I went down was very very very easy. I'm even ashamed to admit that I had spent so much time thinking about it and playing with so many different things to arrive at this point. No.

Turns out the Bitmap object has a very nice constructor (yes, a CONSTRUCTOR! Note emphasis. I really was being that dumb!) that does it all for you. It goes like this:

Dim x as new Bitmap(Original as Image, Width as Integer, Height as Integer)

Dammit! It really hurt to delete the whole bunch of code I'd written only to replace it with one line.

And the even worse part? I haven't even got round to putting together a nice HTML page to put them on yet, so wrapped up have I been with trying to sort out this resizing thing, so my birthday party's still not online yet. When I do it, though, I'll put up a link.

Just wanted to share my stupidity. I'm hoping I'm not the only person who's had experiences like this!

No comments: