Amass

Loading(and then scaling) an image using AS 2.0

March 3rd, 2008 Luke

Have you ever struggled with first loading in, and then scaling an image using ActionScript 2.0?

Loading and scaling images using ActionScript used to be the one thing in Flash that I struggled most with - I just couldn’t seem to find a nice way to get it done. But as it turns out, it’s already been done for me - the MovieClipLoader class exists for exactly the kind of voodoo I need:

var handler:Object = new Object(); handler.onLoadInit = function(mc:MovieClip) { if(mc._width != 200) { mc._width = 200; } if(mc._height != 200) { mc._height = 200; } } var target:MovieClip = createEmptyMovieClip("target",getNextHighestDepth()); var loader:MovieClipLoader = new MovieClipLoader(); loader.addListener(handler); loader.loadClip("my/image/path.jpg",target);

That code, when executed, will load the image at path my/image/path.jpg into the new movie clip we created, and then scale it to 200×200.

Converting Images with C#

December 3rd, 2007 Luke

Have you ever stored an image in your database, only to find that it’s not quite the type of image you’re looking for?

Maybe you’d prefer a PNG or a TIFF, when all you’ve been given is a cruddy old JPEG.

Have no fear! C#’s Image is here!

All you need to do to convert an image from one type to another type is read it into an Image object, and then save it using the mime-type you want.

Image testImg = Image.FromFile("test.jpg"); testImg.Save("test.png", ImageFormat.Png);

And you’re done! Enjoy your shiny new .png file.