java - Blend Bitmap while animation -
i'm developing android application , blend bitmap filter "multiply" or "difference" photoshop. bitmap1 translating horizontally , bitmap2 vertically.
i had few ideas :
1) create method calculation find intersection part of 2 bitmap (requires cross 2 matrix every frame, heavy, seems impossible ?). crop intersection on 2 bitmap, blend them, , draw it. thought anding between 2 bitmap, maybe faster other method, thi function exist ?
2) opengl es ? don't understand how utilize it.
3) have found sample code blend 2 bitmap on canvas , utilize paint. result 1 want there still no animation. i've create new class (extends view) in add-on activity, method ondraw(canvas canvas).
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_compo); bitmap bm1 = bitmapfactory.decoderesource(getresources(), r.drawable.bm1); bitmap bm2 = bitmapfactory.decoderesource(getresources(), r.drawable.bm2); blend(bm1,bm2); } private void blend(bitmap bm1, bitmap bm2){ displaymetrics metrics = new displaymetrics(); this.getwindowmanager().getdefaultdisplay().getmetrics(metrics); int h = metrics.heightpixels; int w = metrics.widthpixels; /// blend mode /// // create result image bitmap.config conf = bitmap.config.argb_8888; // see other conf types bitmap result = bitmap.createbitmap(w, h, conf); canvas canvas = new canvas(); canvas.setbitmap(result); // proper display reference bitmapdrawable drawable = new bitmapdrawable(getresources(), result); imageview imageview = (imageview)findviewbyid(r.id.photo1); imageview.setimagedrawable(drawable); // draw base of operations canvas.drawbitmap(bm2, 0, 0, null); // draw overlay paint paint = new paint(); paint.setxfermode(new porterduffxfermode(mode.multiply)); paint.setshader(new bitmapshader(bm1, tilemode.clamp, tilemode.clamp)); canvas.drawrect(700, 700, bm2.getwidth(), bm2.getheight(), paint); }
here result changing value in 'canvas.drawrect()' :
before translation after translation
do have other solutions ? or suggestions help realize filter on animate views ? (the perfect solutions add together android:blendmode="multiply" in xml, doesn't seem easy)
thank in advance. j'.
java android bitmap blending
No comments:
Post a Comment