1

I have a frame layout with two overlapping bitmaps as imageviews and on touch, the touched pixels only should turn transparent.But instead the entire image turns transparent.

I did refer a similar link Making Overlaid image transparent on touch in Android? But it was of no help.The code for the touchEvent is below.

@Override
public boolean onTouchEvent(MotionEventevent){
startX = (int)event . getX();
startY = (int)event . getY();
switch (event . getAction())
    {
case MotionEvent . ACTION_DOWN:
    return true;
case MotionEvent . ACTION_MOVE:
    try
        {
        newOverlayBitmap = Bitmap . createBitmap(bmp . getWidth() , bmp . getHeight() , bmp . getConfig());
        for (inti = 0; i < bmp . getWidth(); i++)
            {
            for (intj = 0; j < bmp . getHeight(); j++)
                {
                if (i == startX && j == startY)
                    {
                    p = bmp . getPixel(i, j);
                    r = Color . red(p);
                    g = Color . green(p);
                    b = Color . blue(p);
                    alpha = Color . alpha(p);
                    alpha = 256 - alpha;//alpha=1
                    newOverlayBitmap . setPixel(i, j, Color . argb(alpha, r, g, b));
                    }
                }
            }

        img . setImageBitmap(newOverlayBitmap); //sets the changed overlay on the imageview
        }

    catch(Exceptione)
        {
        e . printStackTrace();
        }

    break;

case MotionEvent . ACTION_UP:
    break;

default:
    a = false;
    }

a = true;
super . onTouchEvent(event);
return a;
}
Community
  • 1
  • 1
Apoorva
  • 11
  • 1

0 Answers0