Flash video tutorials

Free Utilities

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 | terms of use | 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 | hittest and magnifying glass | 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 |

Scaling an image – resizing a Bitmap

by admin on November 7, 2008 · 3 comments

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

{ 3 comments… read them below or add one }

1

Gonzalo 12.04.08 at 10:29 pm

Thanks a lot, man! it worked.

2

J 02.07.09 at 5:56 pm

thanks for this snippet, should be in the docs!

3

Sean McAuliffe 03.09.09 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.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Older post:

Newer post: