flash - AS3 How to check if BitmapData is empty -
I have a code to erase the masked movie clip (credit) I would like to know how I can see that the whole movie Whether the clip has been erased or not. So I thought I have to check whether the bitmapdata is empty, but I can be very wrong! How can I check that every pixel of the movie clip has been erased?
Of course my example below is wrong, but I think that something like this should happen.
if (imaging bitmapdata = empty) {trace ("empty")}
var lineSize: number = 40; Var doDraw: boolean = false; Var resume drawing: boolean = false; Var irrelevant bitmap data: bitmapdata = new bitmap data (700, 500, true, 0xFFFFFFFF); Var irrelevant bitmap: bitmap = new bitmap (ereaselbitcapadata); ErasableBitmap.cacheAsBitmap = True; AddChild (erasableBitmap); Maskee.cacheAsBitmap = True; Maski.mask = erasablebitmap; Var Eraserclip: Sprite = New Sprite (); InitEraser (); Function Init Eraser (): Zero {eraserClip.graphics.lineStyle (Linesis, 0xff0000); Eraserclip.graphics.moveTo (stage.mouseX, stage.mouseY); } Drawn drawnBitmapData: bitmapdata = new bitmap data (700, 500, true, 0x00000000); Var drawbitmap: bitmap = new bitmap (drawn bitmapdata); Stage.addEventListener (MouseEvent.MOUSE_MOVE, maskMove); Forum. AddEventListener (Mouse Event.Frols, Mask Out); Stage.addEventListener (MouseEvent.ROLL_OVER, maskOver); Stage.addEventListener (MouseEvent.MOUSE_DOWN, startDrawing); Stage.addEventListener (MouseEvent.MOUSE_UP, stopDrawing); Function Start Drawing (E: Mouse Event): Zero {eraserClip.graphics.moveTo (stage.mouseX, stage.mouseY); DoDraw = true} function stop drawing (e: mouseover): zero {doDraw = false; Resume = false; } Function Mask Out (E: Event): Zero {if (doDraw) {resumeDrawing = true; }} Function MaskOver (E: MouseEvent): Zero {if (resume) insert {resumeDrawing = false; Eraserclip.graphics.moveTo (stage.mouseX, stage.mouseY); }} Function Mask Head (E: MouseEvent): Zero {iframe]; eraserclip.graphics.lineTo (stage.mouseX, stage.mouseY); Prepared wrap data fillerrent (drawn bitmapdata, 0x00000000); Ready-to-read dataadra (AarSclip, new matrix (), blank, blend mode.); ErasableBitmapData.fillRect (erasableBitmapData.rect, 0xFFFFFFFF); ErasableBitmapData.draw (drawnbiltmap, new matrix (), blank, blendmoda.aras); } E.updateAfterEvent (); } Reset_btn.addEventListener (MouseEvent.CLICK, reset); Function Reset (E: Event): Zero {eraserClip.graphics.clear (); InitEraser (); ErasableBitmapData.fillRect (erasableBitmapData.rect, 0xFFFFFFFF); }
You can check whether the Returns the rectangle 0 for those that you consider as 'empty', give false reasoning to findColor . There are other ways to do this, but it is at least several times faster than checking each pixel. FindColor returns the default value of the right to give you a rectangle all the pixels for those (pixel color and mask) == empty collar True, while working with alpha values, a mask of 0xFF000000 can be used to ignore the RBG values of a pixel and only to check its alpha value. So the mask 0xFF000000 and color 0xFF000000 will match all full opaque pixels, whereas the mask 0xFF000000 and color 0x00000000 Will match the transparent pixel as it has been said, it will not work here. By setting false to findColor , this process has been reversed so that all the pixels in the rectangle are added to the not any other color for the bitmap using empty color No, the result will be a rectangle with an area of 0 . var mask color: uint = 0xFF000000; Var empty collar: uint = 0x00000000; Var range: rectangle = erasableBitmapData.getColorBoundsRect (mask color, empty collar, wrong); If (limitations with == 0 and bound HEIGHT == 0) {trace ("empty"); // There is no visual pixel Technically a black transparent pixel 0x00000000 and for example a red transparent pixel 0x00FF0000 There is a difference between - but if there is no difference (both are invisible) then you should completely ignore the RGB values, as I did using that particular mask.
Comments
Post a Comment