Dude you rock! Thanks!

Once the image complete loading I create a scale matrix, maintaining
the aspect ratio and then draw it to a new bitmap, then dispose of the
old data. Saves a ton of memory!

/********** CODE ************/

//When image loaded, create scaled bitmap
private function LoadComplete(evt:Event):void
{
        evt.stopImmediatePropagation(); 
        var loader:Loader = Loader(evt.target.loader);
        var image:Bitmap = Bitmap(loader.content);
        
        var sxy:Number = (image.width > image.height)?
                (95/image.width):(95/image.height);
        var scaleMatrix:Matrix = new Matrix();
        scaleMatrix.scale(sxy,sxy);
                                
        var container:UIComponent = new UIComponent();
        addChild(container);

        var scaledImage:Bitmap = new Bitmap(
                new BitmapData(95,95,true,0));
        scaledImage.bitmapData.draw(image,scaleMatrix);
                                
        container.addChild(scaledImage);
        contentLoader = null;
        image.bitmapData.dispose();
}


--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Scale it, use bitmapData.draw to get the new results
> 
>  
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of Ezekiel48
> Sent: Thursday, May 01, 2008 11:43 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Image Resampling
> 
>  
> 
> I want to create a thumbnail of a picture, but if I just resize the
> picture to say, 95X95 pixels the data of the 6MP picture is still
> loaded into memory so the program take up A LOT of memory. I want to
> resize and/or resample the image to be of a lower resolution so the
> unused data can be cleaned out of memory.
> 
> I have looked around and heard about sending an image to a server to
> be resized but when I need thumbs for a TileList and sending all those
> images to the server would take too long. Does anyone have any
> suggestions? Thanks in advance.
>


Reply via email to