December 6, 2010 - No Comments!

Scale Bitmap with BitmapData and Matrix

Ran into small issue this morning where I needed to scale a bitmap. This was a shot of another movieclip, problem is if you scale the displayobject before taking your shot through bitmapData it doesn't scale the contents you are taking a shot of. In order to get round the issue we use the Matrix class... example code below.

import flash.geom.Matrix;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.MovieClip;

var clip:MovieClip;
var bmpData:BitmapData;
var bmp:Bitmap;
var scale:Number = 0.5;
var matrix:Matrix;
matrix = new Matrix();
matrix.scale(scale, scale);

bmpData = new BitmapData(clip.width * scale, clip.height * scale, true, 0x000000);
bmpData.draw(clip, matrix, null, null, null, true);

bmp = new Bitmap(bmpData, PixelSnapping.NEVER, true);

Published by: nick in AS3, Flash, Flex

Leave a Reply