1

Im having two bitmaps as I want to blend together. Im using a canvas to achieve this. The following code will create a resulting image where the mask is 50% blended into to background.

 Bitmap output = Bitmap.createBitmap(picture.getWidth(),
            picture.getHeight(), Config.ARGB_8888);

    Paint p = new Paint();
    Paint maskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    maskPaint.setAlpha(127);

    Canvas c = new Canvas(output);
    c.drawBitmap(picture, 0, 0, p);
    c.drawBitmap(mask, 0, 0, maskPaint);
    return output;

I have also been expermenting if im able to remove parts of the bitmap, using Xfermode. I have done this with the following code:(This will create a hole, a square)

    int height = BitmapHandler.getMainBitmap().getHeight();
    int width = BitmapHandler.getMainBitmap().getWidth();
    Bitmap bmOverlay = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Paint p = new Paint();
    p.setXfermode(new PorterDuffXfermode(Mode.CLEAR));              
    Canvas c = new Canvas(bmOverlay); 
    c.drawBitmap(BitmapHandler.getMainBitmap(), 0, 0, null); 
    c.drawRect(30, 30, 100, 100, p);

    return bmOverlay;

Now, Im wondering if, using a canvas, I am able to draw a background and a mask and at the same time being able to remove parts of the mask and let the background "shine" through.

Thanks!

4

0 回答 0