How to achieve plumage effect in Android?

I am trying to create an Oval Bitmap and I need to get the feather effect around the fields,

Does anyone have any idea how I can achieve this?

Thank.

+3


source to share


1 answer


You can think of the "pen effect" as a gradient gradient, with the alpha fading from 100% to 0%.

Android offers the RadialGradient class for this purpose. You will want to use a constructor where you can specify control points for the ray, as you want the fade to start at the edge, not in the middle.

One problem with Android's RadialGradient class is that it only supports perfect circles, not ovals. To compensate for this, we simply draw a perfect circle and scale up afterwards.

Sample code:



    private Bitmap makeFeatheredOval(int width, int height) { 

        // Determine largest dimension, use for rectangle.
        int size = Math.max( width, height);

        RadialGradient gradient = new RadialGradient(size / 2, size / 2, size / 2, 
            new int[] {0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF},
            new float[] {0.0f, 0.8f, 1.0f}, 
            android.graphics.Shader.TileMode.CLAMP); 
        Paint paint = new Paint(); 
        paint.setShader(gradient); 

        Bitmap bitmap = Bitmap.createBitmap(size, size, Config.ARGB_8888); 
        Canvas canvas = new Canvas(bitmap); 
        canvas.drawCircle(size / 2, size / 2, size / 2, paint);

        // Scale the bitmap, creating an oval
        bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);

        return bitmap; 
    }

      

Sample image (this is the oval "moon" in the upper left corner):

Oval circle overlayed on demoscene awesomeness

Bonus points for anyone who recognizes this background image.

+9


source







All Articles