4 Replies Latest reply on Aug 6, 2007 12:21 AM by Marcus_House

    Fill tool (like in MS paint or photoshop) done on bitmapdata / bytearray

    marcus_house Level 1
      Hi All,

      I wanted to implement a real fast "Fill Tool" into a flash app that I am making.
      e.g. user selects a colour. and clicks over a pixel on a bitmap. The tool then fills pixels with the colour up to a certian tolerance etc.

      I have currently written one but it is very slow. I'd like to be able to perfom a fill on a 1600x1200 blank image and have it do that with a second. (or even a few seconds)
      Currently it may take a few seconds to fill a 640 x 480 image.

      Has anyone written a real fast way to fill in this way?
        • 1. Re: Fill tool (like in MS paint or photoshop) done on bitmapdata / bytearray
          kglad Adobe Community Professional & MVP
          use the floodFill method of bitmaps if you're not testing pixels against a threshold and use the threshold method if you are testing pixels against a threshold.
          • 2. Re: Fill tool (like in MS paint or photoshop) done on bitmapdata / bytearray
            Marcus_House
            Hmmm..
            Interesting... I'll give this a try and let you know how I go.. Not a bad idea. And probably much easier and faster than trying to get actionscript to do that manually.
            • 3. Re: Fill tool (like in MS paint or photoshop) done on bitmapdata / bytearray
              kglad Adobe Community Professional & MVP
              yes, the native flash methods are much faster the compiled actionscript.
              • 4. Re: Fill tool (like in MS paint or photoshop) done on bitmapdata / bytearray
                Marcus_House Level 1
                Ok. I think we are on the right track here but I have a problem.
                The threshold method will colour the entire image at a certian tolerance. However this is not what I want. This is more of a contiguous fill. I want a fill that flows from one point.
                By using a combination of threshold to draw the fillable pixels, then using the floodfill method on that result I am able to get somethign close. HOWEVER... I do not really fully understand how the threshold method is working.
                I want to fill based on color difference. e.g. when you click ona blue I want it to fill colours close to that blue (up to a certain tolerance).
                Do you know how I could achieve this? So far I am doing this.. it is currently based on greyscale.. But I am really not 100% sure how the threshold is working. I'd rather have one based on coloru closeness but when I try to do this is all goes haywire on me.
                Suggestions?

                var low:int = toolFill_greyLevel-toolFill_tolerance;
                var high:int = toolFill_greyLevel+toolFill_tolerance;

                if(low<0)
                {
                low = 0;
                }
                if(high>255)
                {
                high=255;
                }
                //clear bitmap data
                var fillCol:uint=0x01FFFFFF;
                toolFill_bd.fillRect(rect, 0x00000000); //clear image
                toolFill_bd.threshold(loadedImageGreyScaleBitmapData, rect, new flash.geom.Point() , ">", low << 16 ^ low << 8 ^ low , 0x01BBBBBB, 0x00FFFFFF, false);
                toolFill_bd.threshold(loadedImageGreyScaleBitmapData, rect, new flash.geom.Point() , ">", high << 16 ^ high << 8 ^ high , fillCol, 0x00FFFFFF, false);
                toolFill_bd.setPixel32(toolFill_downPixX, toolFill_downPixY, fillCol);
                toolFill_bd.floodFill(toolFill_downPixX,toolFill_downPixY, 0xFF00CC00);