0

In my app I blend 2 Bitmaps, one Bitmap is on the screen and when i Swipe with my finger it reveals the matching pixels from the second Bitmap. The way I have now works but when I touch the screen it only reveals squares from the other Bitmap since pixels are squares, and I'm revealing a group of them by touching the screen. How do I group pixels together to create a circle?

This is my current code:

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    if (!surfaceReady)
        return false;

    // Check if the touch pointer is the one you want
    if (event.getPointerId(event.getActionIndex()) == 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            // User touched screen...

        case MotionEvent.ACTION_MOVE:
            // User dragged his finger...
            blend((int) event.getX(), (int) event.getY());

        }
        // Update the blending effect bitmap here and trigger a frame
        // redraw,
        // if you don't already have an animation thread to do it for you.
        drawOverlays();
        return true;
    }

    return false;
}

And the blending code:

// In order to make the effect more "visible" I've created a larger brush
 public  int BS = 50;
 public  int HBS = BS >> 1;
int[] pixels = new int[BS * BS];

private void blend(int x, int y) {
    if (x >= HBS && y >= HBS && x < bmp2.getWidth() - HBS && x < operation.getWidth() - HBS && y < bmp2.getHeight() - HBS && y < operation.getHeight() - HBS) {
        bmp2.getPixels(pixels, 0, BS, x - HBS, y - HBS, BS, BS);
        operation.setPixels(pixels, 0, BS, x - HBS, y - HBS, BS, BS);
    }
}
Jonah G
  • 91
  • 1
  • 1
  • 14
  • I'd look into PorterDuff modes. Create a mask bitmap containing a white circle on a black background, and use the porterduff mode to blit the 'bmp2' pixels onto 'operation'. – xorgate Mar 16 '15 at 16:16
  • Do you have a link to somewhere with an explenation? – Jonah G Mar 16 '15 at 16:53

0 Answers0