android - How to make glow effect around a bitmap? -
the following code got far. however, there 2 issues:
i want both inner , outer glow effects, similar photoshop's blending options. managed make outer glow, if set
blurmaskfilter.blur.inner
or other value, whole image blocked, instead of edges.despite set "ff" alpha value, glow color still dark.
bitmap alpha = origin.extractalpha(); blurmaskfilter blurmaskfilter = new blurmaskfilter(5, blurmaskfilter.blur.outer); paint paint = new paint(); paint.setmaskfilter(blurmaskfilter); paint.setcolor(0xffffffff); canvas canvas = new canvas(origin); canvas.drawbitmap(alpha, 0, 0, paint); return origin;
try one.
private void setbackgroundglow(imageview imgview, int imageicon,int r,int g,int b) { // added margin initial image int margin = 24; int halfmargin = margin / 2; // glow radius int glowradius = 40; // glow color int glowcolor = color.rgb(r, g, b); // original image use bitmap src = bitmapfactory.decoderesource(getresources(),imageicon); // extract alpha source image bitmap alpha = src.extractalpha(); // output bitmap (with icon + glow) bitmap bmp = bitmap.createbitmap(src.getwidth() + margin, src.getheight() + margin, bitmap.config.argb_8888); // canvas paint on image canvas canvas = new canvas(bmp); paint paint = new paint(); paint.setcolor(glowcolor); // outer glow paint.setmaskfilter(new blurmaskfilter(glowradius, blur.outer));//for inner glow set blur.inner canvas.drawbitmap(alpha, halfmargin, halfmargin, paint); // original icon canvas.drawbitmap(src, halfmargin, halfmargin, null); imgview.setimagebitmap(bmp); }
Comments
Post a Comment