svKris
svKris

Reputation: 783

convert masked movieclip into bitmap and save it on server

i have a dsgnArea----> a movieclip

dsgnArea is masked by dsgnAreaMask, which inturn is a movieclip

dsgnArea.mask=dsgnAreaMask;

the width,height and position of dsgnAreaMask and dsgnArea are same.

i dynamically added multiple movieclips and labels to dsgnArea; like.. dsgnArea.addChild(movieClip1); dsgnArea.addChild(movieClip2); dsgnArea.addChild(label1); dsgnArea.addChild(label2); and so on...

       these movieclips (movieClip1,movieClip2,......) and labels(label1,label2,....) positions can be altered in runtime..

but as i masked the dsgnArea with dsgnAreaMask, only a portion of the added movieClips and labels are visible...

So, my problem is to grab that visible portion in dsgnArea into a bitmap,like a screenshot of that particular dsgnArea, and save it in my server.

please help me out in this problem.

Upvotes: 0

Views: 1598

Answers (3)

nicoptere
nicoptere

Reputation: 1069

Quasimondo did a handy little method to do this (take a snapshot of the whole displayObject), it's available here: http://www.quasimondo.com/archives/000670.php

I don't know if it works with masked content though. if it doesn't, the trick would be to translate the whole content by the size of the mask

var bounds:Rectangle = dsgnAreaMask.getBounds( dsgnAreaMask );

instead of using the content of the clip

var bounds:Rectangle = clip.getBounds( clip );

as far as saving file to server is concerned, the question was asked (answered?) here AS3 Save Media File to server

Upvotes: 0

Manish
Manish

Reputation: 3522

Say s is the DisplayObject object you want to capture and m is the mask applied on it.

var maskRect:Rectangle = m.getRect(s);
var matrix:Matrix = new Matrix(1, 0, 0, 1, -maskRect.x, -maskRect.y);

var w:Number = Math.min(s.width, maskRect.right) - maskRect.x;
var h:Number = Math.min(s.height, maskRect.bottom) - maskRect.y;

var bd:BitmapData = new BitmapData(w, h);
bd.draw(s, matrix);

Does that work?

Upvotes: 1

maxmc
maxmc

Reputation: 4216

The BitmapData draw method is what you are looking for. You can use it's clipRect param to define what you would like to draw (the masked parts).

Upvotes: 0

Related Questions