how to capture whole layout when layout exceeds screensize in android -
in application zooming layout when zoom layout want capture layout.i tried below code capturing content visible in screen.please me how capture layout.
view content = findviewbyid(r.id.main_container); content.setdrawingcacheenabled(true); bitmap bitmap = content.getdrawingcache(); // actual width of image (img bitmap object) // int width = bitmap.getwidth(); // int height = bitmap.getheight(); // recreate new bitmap , set bitmap = bitmap.createbitmap(bitmap.createbitmap( l1.getwidth() * 2, l1.getheight() * 2, bitmap.config.argb_8888)); // bitmap mb = bitmap.copy(bitmap.config.argb_8888, true); canvas bitmapcanvas = new canvas(); bitmapcanvas.setbitmap(bitmap); bitmapcanvas.scale(2.0f, 2.0f); content.draw(bitmapcanvas); bytearrayoutputstream out = new bytearrayoutputstream(); bitmap.compress(bitmap.compressformat.png, 100, out); file imagesfolder = new file(environment.getexternalstoragedirectory(), "saved_images"); imagesfolder.mkdirs(); string filename = "final-" + string.valueof(n) + ".jpg"; file output = new file(imagesfolder, filename); while (output.exists()) { n++; filename = "final-" + string.valueof(n) + ".jpg"; output = new file(imagesfolder, filename); } uri urisavedimage = uri.fromfile(output); outputstream imagefileos; try { imagefileos = getcontentresolver().openoutputstream(urisavedimage); imagefileos.write(out.tobytearray()); imagefileos.flush(); imagefileos.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } content.setdrawingcacheenabled(false);
here's way grabbing screenshot of layout. i'm writing out of head code may contain errors (can't verify right now);
viewgroup bg = (viewgroup) findviewbyid(r.id.your_layout_id); bitmap screenshot = bitmap.createbitmap(vg.getwidth(), vg.getheight(), bitmap.config.rgba8888); canvas c = new canvas(screenshot); vg.draw(c);
now i'm not sure whether works better should draw @ least according documentation.
Comments
Post a Comment