android - Exporting multiple bitmaps to one picture -


i've got 2 imageviews within relativelayout. 1 imageview draggable , scalable upon other imageview. works fine except when try export imageviews bitmap , add canvas.

i can't figure out how calculate scale , dragged position of view/bitmap b.

imageview functions background.
imageview b draggable , scalable on top of imageview a.

enter image description here

here code example

    public static bitmap mergebitmaps(view v, view viewa, bitmap bitmapa, view viewb, bitmap bitmapb) {     bitmap b = bitmap.createbitmap(             bitmapa.getwidth(), bitmapa.getheight(), bitmap.config.argb_8888);     canvas c = new canvas(b);      float scalefactor = (float) viewa.getheight() / (float) bitmapa.getheight();     float scalefactorwidth = (float) viewa.getwidth() / (float)bitmapa.getwidth();      int test2[] = new int[2];     viewb.getlocationonscreen(test2);      //rect rect1 = new rect();     //selectedimg.getdrawingrect(rect1);      //rect rect2 = new rect();     //logo.getdrawingrect(rect2);     //int logoheight = logo.getheight();     //int logowidth = logo.getwidth();      //int logoleft = logo.getleft();     //int selectedimgleft = selectedimg.getleft();     float scalefactormid = (scalefactor + scalefactorwidth)/2;       c.drawbitmap(bitmapa, 0, 0, null);     //c.drawbitmap(logobitmap, test2[0]*scalefactorwidth, test2[1]*scalefactor, null);     bitmapb = getresizedbitmap(bitmapb, (int)(bitmapb.getheight()*scalefactormid), (int)(bitmapb.getwidth()*scalefactormid));     c.drawbitmap(bitmapb, bitmapa.getwidth()/2, bitmapa.getheight()/2, null);     //v.layout(0, 0, v.getwidth(), v.getheight());      //selectedimg.draw(c);     return b; } 

i tried calculating scale factor dividing view's width/height , bitmaps width/height.

i tried lot more can see. can point me in right direction?

for reference below function helpful,(in scaled bitmap statically, can move code).

public void mergetwobitmap() {     imageview iv1 = (imageview) findviewbyid(r.id.imageview1);     imageview iv2 = (imageview) findviewbyid(r.id.imageview2);     bitmap bitmap1 = ((bitmapdrawable) iv1.getdrawable()).getbitmap();     bitmap bitmap2 = ((bitmapdrawable) iv2.getdrawable()).getbitmap();      float img2x = iv2.getx(), img2y = iv2.gety();     float img2width = bitmap2.getwidth(), img2height = bitmap2.getheight(); // original width , height      bitmap2 = bitmap.createscaledbitmap(bitmap2, 300, 300, true);      float img2newx, img2newy;     img2newx = img2x + (img2width - bitmap2.getwidth()) * 0.5f; // here bitmap2.getwidth() after scale bitmap1     img2newy = img2y + (img2height - bitmap2.getheight()) * 0.5f; // here bitmap2.getheight() after scale bitmap2      bitmap b = mergebitmap(iv1.getwidth(), iv1.getheight(), bitmap1,             bitmap2, img2newx, img2newy); }   private bitmap mergebitmap(float w, float h, bitmap bmp1, bitmap bmp2,         float x, float y) {     bitmap cs = null;     int width = (int) w, height = (int) h;     cs = bitmap.createbitmap(width, height, bitmap.config.argb_8888);     canvas comboimage = new canvas(cs);     comboimage.drawbitmap(             bitmap.createscaledbitmap(bmp1, width, height, true), 0f, 0f,             null);     comboimage.drawbitmap(bmp2, x, y, null);     return cs; } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -