How to make an external glow effect around a bitmap?

I created a glow effect for my bitmap. His work, but I have an emblem with my outer glow.

This is my expected design for the outer glow color:

http://www.flashcomponents.net/component/professional-3d-carousel-as2-and-as3.html , see link

but my glow effect doesn't look good, please help me how to make the expected glow effect? This is my code:

public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int margin = 24; int halfMargin = margin / 2; // the glow radius int glowRadius = 16; // the glow color int glowColor = Color.rgb(0, 192, 255); // The original image to use Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); // extract the alpha from the source image Bitmap alpha = src.extractAlpha(); // The output bitmap (with the icon + glow) Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin, Bitmap.Config.ARGB_8888); // The canvas to paint on the image Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setColor(glowColor); // outer glow paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER)); canvas.drawBitmap(alpha, halfMargin, halfMargin, paint); // original icon canvas.drawBitmap(src, halfMargin, halfMargin, null); ((ImageView) findViewById(R.id.bmpImg)).setImageBitmap(bmp); } } 

I am new to android, I only need programmatically .....

enter image description here

The expected glow in my back of the image, please see my expected screenshot: enter image description here

+4
source share
1 answer

I am sure that it is not possible to do this only programmatically, unless you want to use an overly complex method using OpenGL.

Instead, you can try the following:

Make a 9-patch png, which is a box with an external shadow around it, and the content labels (on the right and bottom) are inside the white part. Then set this against the background of any element to which you want to add a shadow. Here is one that found what should give you an idea of ​​what to use:

If you are not familiar with 9-patch images read about them here

outer shadow box

Note. You need to save it as <filename>.9.png . This 9.png very important. If you omit 9 , this will not work.

You can delete the specified image in draw9patch and adjust the sides if you need more or less spaces.

-1
source

Source: https://habr.com/ru/post/1438851/


All Articles