AS3:How to change a colored Bitmap's BitmapData to black and white?

前端 未结 7 963
一整个雨季
一整个雨季 2020-12-14 13:35

How can I change the bitmapdata of a coloured Bitmap to Black and White in AS3 ? I\'m developing a simple image editor tool for a CMS in f

7条回答
  •  醉话见心
    2020-12-14 14:12

    Well, just using getPixel and setPixel, and averaging the colors (I'm sure there may be another way to do this with a filter or something):

    for(int i = 0; i < bitmapData.height; i++)
    {
        for(int j = 0; j < bitmapData.width; j++)
        {
            var color:uint = bitmapData.getPixel(i, j);
            var red:uint = color & 0xFF0000 >> 16;
            var green:uint = color & 0x00FF00 >> 8;
            var blue:uint = color & 0x0000FF >> 0;
            var bwColor:uitn = red + green + blue / 3;
            bwColor = bwColor << 16 + bwColor << 8 + bwColor; // puts the average in each channel
    
            bitmapData.setPixel(i, j, bwColor);
        }
    }
    

提交回复
热议问题