views:

1206

answers:

4

Hello all,

I am trying to take a snapshot of the masked region of an image... so, I load my image then perform the following functions:

private function manageLoadedImage(e:Event):void
  {

   _bitdata = e.currentTarget.content; // get the bitmap

   _bithold.addChild( _bitdata ); // add the bitmap to a sprite on the stage

   _bithold.x = holder1.x -((_bithold.width - holder1.width)/2); // center image

   _bithold.y = holder1.y -((_bithold.height - holder1.height)/2); // center image

   var m:Shape = new Shape(); // create the shape

   m.graphics.beginFill(0x0); // make the fill

   m.graphics.drawRect( this.x, this.y, holder1.width, holder1.height ); // draw the mask

   m.graphics.endFill(); // end the fill

   _bithold.mask = m; // mask the image


  }// private function manageNewPaneAddition(e:Event):void

public function save( ):void
  {

                          // WHAT DO I DO HERE ????????

   _bmdsrc = new BitmapData( holder1.width, holder1.height ); // create the new bitmapdata

    var m:Matrix = _bithold.transform.matrix; // lets try this out

    m.tx = -holder1.x + _bithold.width; // not sure what this means ?

    m.ty = -holder1.y + _bithold.height; // what does this mean ?

   _bmdsrc.draw( _bithold, m); // draw the bitmapdata

                        // END PROBLEM ??????????????

  }// private function save(  ):void

So, after I manage the loaded image, I save it. But the save function only outputs a white square 80x80px. This tells me that I am snapshot-ing a blank stage.

The MovieClip construction is as follows:

I have a movie, inside that movie I have a thumbnail editor name ThumbEdit.

ThumbEdit has a movieclip on its stage called "holder1". In the document class of ThumbEdit I create a sprite "_bithold" and place it on the stage at holder1.x and holder1.y. When the image loads, I add the image to _bithold and then mask _bithold with a shape. So, I want to grab a snapshot of the masked region of _bithold but I'm not sure how I should go about doing that... any advice?

Thanks for your time. nG

+1  A: 

You can try using BitmapData.copyPixels().

bhups
A: 

I decided to use Library movieclips instead. I created a frame with a masked movieclip the size I needed inside of a MovieClip that is on the stage.

So, on the stage I have the movieclip named "Snap". Inside snap is two layers, mask and holder, both are Movieclips.

When the bitmap loads, I add it to the holder movieclip which is masked appropriately by the mask layer. Then, I take a snapshot of the "Snap" movieclip.

I probably could have sorted it out programmatically, but this was much faster and very simple.

Thanks for your time.

Cinegod
+1  A: 

Hello, friend.

There are some approach to achieve what you need. The simpliest is to use BitmapData with Matrix classe, just as you've done.

The save method seems to be correct, except for the references and maybe the coords are not right. Your save method should look like this, considering that _mask is the shape masking the content, and _bithold is the masked movieclip:

public function save( ):void
{

   _bmp = new BitmapData( _mask.width, _mask.height ); // creates the bitmap of the mask's size

   var m:Matrix = new Matrix();
       m.translate( -_mask.x, -_mask.y ); // Create the matrix used to translate the positions of the source image.

   _bmp.draw( _bithold, m); // draw the bitmapdata considering the offset of the mask


   addChild( new Bitmap(_bmp) ); // just attaching the result on the screen, to see the result.

}

It is important to notice, that the line that translates the matrix object, must input values relatives to the _bithold movieclip. It means that if the mask shape and the masked object (_bithold) aren't in the same parent, you need to bring the coords to the movieclip parent, with globalToLocal and localToGlobal methods.

Any other doubt, I'll be here!

Cheers, CaioToOn!

CaioToOn
cool! Thanks for the help. I implemented a simple timeline solution now, but will try yours in the near future. Then will post back here.
Cinegod
A: 

@ CaioToOn!

Thanks man .. your save function is working awesome ...

I was working on it for hours .. My search ended at this page...

Thanks and Regards Inder

Inder