dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Creating masks from bitmapData

  1. #1
    Member
    Join Date
    May 2009
    Posts
    62

    Creating masks from bitmapData

    I'm trying to modify the alpha layer of a bitmapData by taking a source iamge and masking out areas that don't have the correct channel. ATM I'm using copyChannel to achieve the effect, but I'd liek more than 3 channels (use alpha kills the other channels it seems). 255, 0, 255 should be able to act as another mask.

    This is what I'm doing now...
    Code:
    bitmap.bitmapData.copyChannel(tempMask, new Rectangle(0, 0, tempMask.width, tempMask.height), new Point(0, 0), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
    So the red parts of the image mask out the source image. All I want is to be able to mask out things basic on multiple channels (the lesser of the 2).

    So, I'm wondering two things.
    1) How does copyChannel work? Can I just test each pixel manually and achieve relatively similar speeds?

    and 2) if the Flash inline functions are infact faster, is there a function that can do what I want, or would it be better to use a shader?

    Edit:
    I found one solution, not sure it's the best, thoguh.

    Code:
    var tempBitmapData:BitmapData = new BitmapData(tempMask.width, tempMask.height);
    var matrix:Array = [];
    matrix = matrix.concat([0, 0, 0, 0, 0]); // red
    matrix = matrix.concat([0, 0, 0, 0, 0]); // green
    matrix = matrix.concat([0, 0, 0, 0, 0]); // blue
    matrix = matrix.concat([1, 0, 1, 0, -255]); // alpha
    
    tempBitmapData.applyFilter(tempMask, new Rectangle(0, 0, tempMask.width, tempMask.height), new Point(0, 0), new ColorMatrixFilter(matrix));
    				
    bitmap.bitmapData.copyChannel(tempBitmapData, new Rectangle(0, 0, tempBitmapData.width, tempBitmapData.height), new Point(0, 0), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
    Using 2 filter commands is bound to be painfully slow.
    Last edited by Sharsnik; 10-17-2009 at 09:49 AM.

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    objectToMask.mask = maskObject;

    use the mask property, it should also work with bitmaps if the property is inherited

    flos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center