android - Apply many color filters to the same drawable -
i want apply several color filters in chain drawable. possible? or maybe create filter combination of filters want apply.
for example, like:
drawable d = ...; d.setcolorfilter(0x3f000000, mode.overlay).setcolorfilter(0xff2d2d2d, mode.screen)
this approach ended using: manipulate drawable
bitmap on canvas
, apply many layers need, using paint
, works not color filters, kind of image blending.
... drawable mybackground = createbackground(getresources().getcolor(r.color.green)); setbackgrounddrawable(mybackground); ... private drawable createbackground(int color) { canvas canvas = new canvas(); bitmap buttonimage = bitmapfactory.decoderesource(getresources(), r.drawable.btn_image); bitmap buttonshadows = bitmapfactory.decoderesource(getresources(), r.drawable.btn_shadows); bitmap buttonhighlights = bitmapfactory.decoderesource(getresources(), r.drawable.btn_highlights); bitmap result = bitmap.createbitmap(buttonimage.getwidth(), buttonimage.getheight(), bitmap.config.argb_8888); canvas.setbitmap(result); paint paint = new paint(); paint.setfilterbitmap(false); // color paint.setcolorfilter(new porterduffcolorfilter(color, mode.multiply)); canvas.drawbitmap(buttonimage, 0, 0, paint); paint.setcolorfilter(null); // shadows paint.setxfermode(new porterduffxfermode(mode.multiply)); canvas.drawbitmap(buttonshadows, 0, 0, paint); // highlights paint.setxfermode(new porterduffxfermode(mode.screen)); canvas.drawbitmap(buttonhighlights, 0, 0, paint); paint.setxfermode(null); return new bitmapdrawable(getresources(), result); }
caveat: setbackgrounddrawable(drawable d)
deprecated, while setbackground(drawable d)
available api 16 on, if have me min target api-14 max target api-17 have no "clean" way set drawable background. sticked deprecated call.
I am Android-Java Programmer.
ReplyDeleteI am searching "How to use canvas.setBitmap(Bitmap bitmap)".
And Find "How to use Drawable" at this site.
Thanx !!