Slice Images With A Matrix

26 April 2009

For my current project I needed something to slice an image easily, first I tried to slice the image with a mask, but I soon found out that this much heavier than my current solution.

Lukxexample

Below is the end result I needed to have (the triangle is a big mask).

// image = a MovieClip with an image
 
// upper part
var upperBitmapData:BitmapData = new BitmapData(image.width,image.height / 2);
upperBitmapData.draw(image);
 
mUpperBitmap = new Bitmap(upperBitmapData);
addChild(mUpperBitmap);
 
//lowerpart
var lowerMatrix:Matrix = new Matrix();
lowerMatrix.ty = -(image.height / 2); 
 
var lowerBitmapData:BitmapData = new BitmapData(image.width,image.height / 2);
lowerBitmapData.draw(image,lowerMatrix);
 
mLowerBitmap = new Bitmap(lowerBitmapData);
mLowerBitmap.y = ContentClip.MASK_HEIGHT / 2;
addChild(mLowerBitmap);
 
image = null;
Jankees van Woezik profile picture

Hello, I'm Jankees van Woezik

Like this post? Follow me at @jankeesvw on Twitter