Android AvoidXfermode deprecated with API 16, is there a replacement?

I need to draw a bitmap on another bitmap, but I only want to draw on top of the pixels with a specific color (in this case transparent). I understand that it AvoidXfermodecan do this, but it is deprecated with API 16. Is there any other way for this now?

thank

+5
source share
2 answers

I received the correct answer in my personal inbox, so I will tell you here: There is no replacement method. AvoidXfermodeDeprecated because it is not supported by hardware. However, it can be used when drawing bitmap images.

, , , , , .

+4

, .

var image1, image2;

var newCanvas = document.createElement('canvas');
var newContext = newCanvas.getContext('2d');
newCanvas.width = image1.width;
newCanvas.height = image1.height;
newContext.drawImage(image1, 0, 0);
var imgData = newContext.getImageData(0,0,newCanvas.width, newCanvas.height);
newContext.drawImage(image2, 0, 0);
var imgData2 = newContext.getImageData(0,0,newCanvas.width, newCanvas.height);

for (var i = 0; i < imgData.data.length; i += 4) {
    if( imgData.data[i] < 20        //If Red is less than 20
        && imgData.data[i+1] == 40    //If Green is 40
        && imgData.data[i+2] >= 240   //If Blue is over 240
        && imgData.data[i+3] >= 240) //If Alpha is over 240
    {
        imgData.data[i] = imgData2.data[i];
        imgData.data[i+1] = imgData2.data[i+1];
        imgData.data[i+2] = imgData2.data[i+2];
        imgData.data[i+3] = imgData2.data[i+3];
    }
}
imgData2 = null;
newContext.putImageData(imgData, 0, 0);

, - .

imgData, , putImageData, ( )

+1

All Articles