4

I've managed to draw a custom shape onto a canvas and use that shape as a mask over an image. Is there anyway possible to crop the image and save it out in the custom shape? making whatever is outside the shape transparent? The only image cropping i can find is using rectangles, whereas i need a polygon shape....

Any help would be much appreciated. And thanks in advance!

MattBH
  • 1,562
  • 3
  • 24
  • 31
  • maybe you can draw the masked image into a Bitmapdata, which you can use for a new Bitmap. Then mask this Bitmap for cropping purpose, draw it again into new Bitmap which you save. As far as i know does flash support transparent pixels, but i don't know if there is a libray for saving the images. – philipp Jun 03 '11 at 12:22
  • but how would i set the pixels outside of the mask to transparent? – MattBH Jun 03 '11 at 13:21
  • 2
    So if i understand you right, than you have got an rectangular Bitmap you want to crop with poly line. All space outside should be transparent. So mask this bitmap with an regular mask and draw it into the bitmapdata of a new Bitmap. Make sure that your new Bitmap is initialisised with transparency. Then you can use the draw() method of this bitmapdata object, or the getPixels32() method to get the data of the masked bitmap. Your new Bitmap shouls now have transparent space outside. That is just a workarround, because you cannot mask a bitmap twice – philipp Jun 03 '11 at 13:34
  • 1
    Post the code so I don't have to guess – The_asMan Jun 03 '11 at 16:29

1 Answers1

1

first you need this: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#draw()

second you should set it up like a movieclip with the image inside and mask the movieclip ([MovieClip].mask) with a shape, or whateve then parse it to the draw method of a new bitmap data.

you can capture anything like this that can be rendered inside flash.

encoder
  • 26
  • 1