versione italiana versione italiana
FlepStudio logo

Actionscript 3.0 Blog with Tutorials and free resources for Flash

>> Free Flash files

Events Scroller | Images Scroller | Multi FLV Player | Flash CS3 GuestBook | News Scroller | Tortillas - creator of simple graphs for statistical data | 3D images visualization free utility | Flash CS3 Uploader - free utility | Mini Gallery | Flash CS3 puzzle | Hit counter Flash CS3 + XML + PHP | Multi Audio Player | Newsletter module | Bluring Slide | Monthly Calendar | ShoutBox | StripGallery - Flash CS3 and XML gallery | Email Form PRO | MaskMenu | Elastic Gallery | PhotoNavigator | Pixellation - SlideShow | Email form | Analogue clock | FullScreen images gallery | Rotating header | Flash Portfolio | Polls System | Products Exhibitor | Mini Navigator | Drag Menu | Horizontal Menu | Quizzer | Mini Navigator 2 | Reflect Gallery | Events Scroller - version 2 | Rotating header 2 | Magnifying Glass | Zoomify | MenuVibration | Email form Flash CS3 and ColdFusion 8 | News Scroller 2 | Simple GuestBook | Captcha for Flash CS3 | Email form with pictures - Flash CS3 and PHP | FlepCharCode | Mac Menu | Header | Memory Game - Flash CS3 game | Flash CS3 CountDown | FLV Slide Show Videos | Illusion - images gallery | Tell A Friend | Flash RSS reader | ToolTip Flash CS3 - CS4 | Sliding Email Form | ComboMenuHeader | ComboMenuHeader PRO | Mac Front Row in Flash CS3 | FlaTwit - Flash and Twitter - twit this | Store Locator | Multi Video Player MAC style | Flash XML editor | BlurSlideShow | ImagesViewer | Video Gallery | Flash XML editor gallery 1 | 15 numbers game | Tipper vertical scroller with Iphone effect | YouTube Video Player by categories | GuestBook Flash CS4 | tweened menu | Twitter RSS reader | Xmas Flash header | Events Scroller - version 3 | TripleBox | BlackComboBox | Inertial Photo Portfolio | Fullscreen Background | Multi Categories Images Gallery | DropDown menu | CountDown version 2 | Advertising Flash banner | Quizzer version 2 | UEFA RSS reader | Flash Scrolling Portfolio | Video Player | Flash Gallery | Images Scroller version 2 | Images Scroller version 3 | Images Scroller version 4 | Europe map | Events slide show | Banner Rotator | Flash and Flickr image gallery | Flash and Picasa image gallery

Scaling an image – resizing a Bitmap

by admin on November 7, 2008

in Flash CS3,Mix,Tutorials

When a bitmap (image) is reduced by using the methods scaleX and scaleY or width and height, the same bitmap seems to have changed but the size really does not.
This is because the BitmapData of the image has remained the same, then the weight and memory are same even if we had scaled down the image to 10%.

To resize and then actually gain weight and memory we must use the draw method of BitmapData class (of which we have already seen an example) and the Matrix class.

Very useful to create thumbnails.

The steps are as follows:

  1. Retrieve a temporary reference to the original Bitmapdata object.
  2. Draw a scaled version of the original BitmapData object into a new BitmapData object.
  3. Associate the original Bitmap object with the new, scaled Bimapdata object.

Here is the code:

1
2
3
4
5
6
7
8
9
var originalBitmapData:BitmapData=originalBitmap.bitmapData;
var scaleFactor:Number=0.5;
var newWidth:Number=originalBitmapData.width*scaleFactor;
var newHeight:Number=originalBitmapData.height*scaleFactor;
var scaledBitmapData:BitmapData=new BitmapData(newWidth,newHeight,true,0xFFFFFFFF);
var scaleMatrix:Matrix=new Matrix();
scaleMatrix.scale(scaleFactor,scaleFactor);
scaledBitmapData.draw(originalBitmapData,scaleMatrix);
originalBitmap.bitmapData=scaledBitmapData;
Share This Post

Related posts

{ 4 comments… read them below or add one }

1 Gonzalo December 4, 2008 at 10:29 pm

Thanks a lot, man! it worked.

2 J February 7, 2009 at 5:56 pm

thanks for this snippet, should be in the docs!

3 Sean McAuliffe March 9, 2009 at 9:24 pm

This seems cool and I’ve tried a small example but could you give me an example of why I would do this? I thought I would see some difference in file size or something — when you say “actually gain weight and memory” could you be more specific?

Thanks in advance.

4 Matthias March 22, 2010 at 12:15 pm

Thanks a lot!

@Sean: For us, it came in handy as Flash’s Bitmap-class tends to draw incorrect BitmapData if their scaling is REALLY small (like 0,02).

Leave a Comment

{ 1 trackback }

Previous post:

Next post: