androidonclickiconseffectsbacklight

How to make an android icon image edge be highlightened on clicking it


My problem is simple: how to make same android homescreen icon effect on clicking them? In other words how to make that temporary back lighting effect? In general how to implement android image buttons backlight effect that surround picture edge? Possibly I want to make it programmatically without insert a lot of images in my app. Thanks in advance.


Solution

  • I found something working:

       public Bitmap highlightImage(Bitmap src) {
            // create new bitmap, which will be painted and becomes result image
            Bitmap bmOut = Bitmap.createBitmap(src.getWidth() , src.getHeight() ,   Bitmap.Config.ARGB_8888);
            // setup canvas for painting
            Canvas canvas = new Canvas(bmOut);
            // setup default color
            canvas.drawColor(0, PorterDuff.Mode.CLEAR);
            // create a blur paint for capturing alpha
            Paint ptBlur = new Paint();
            ptBlur.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
            int[] offsetXY = new int[2];
            // capture alpha into a bitmap
            Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
            // create a color paint
            Paint ptAlphaColor = new Paint();
            ptAlphaColor.setColor(0xFFFFFFFF);
            // paint color for captured alpha region (bitmap)
            canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
            // free memory
            bmAlpha.recycle();
    
            // paint the image source
            canvas.drawBitmap(src, 0, 0, null);
    
            // return out final image
            return bmOut;
        }
    

    You can use this method for example in an onclick button to highlight edge of a bitmap