android - how to capture a bitmap from a view with its parent background -


i want create bitmap view , have bitmap contain background parent view(s).

the following code capture view "v":

  v.builddrawingcache();   bitmap b = bitmap.createbitmap (v.getdrawingcache()); 

but background of "v". in case, "v" has transparent background, "b" has transparent alpha channel. want "b" contain actual displayed background.

ideas?

i can suggest following solution. can have several parents semitransparent backgrounds can capture whole activity window , crop part need (your view bounds).

for example:

    view root = getwindow().getdecorview().getrootview();     root.setdrawingcacheenabled(true);     root.builddrawingcache();     // here got whole screen bitmap     bitmap screenshot = root.getdrawingcache();      // view coordinates     int[] location = new int[2];     view.getlocationinwindow(location);      // crop screenshot     bitmap bmp = bitmap.createbitmap(screenshot, location[0], location[1], view.getwidth(), view.getheight(), null, false); 

after doing can sure bitmap contains actual displayed background.

upd: if root.getdrawingcache() doesn't work can capture screen directly drawing on bitmap:

    view root = getwindow().getdecorview().getrootview();     bitmap screenshot = bitmap.createbitmap(root.getwidth(), root.getheight(), bitmap.config.argb_8888);     canvas canvas = new canvas(screenshot);     root.draw(canvas); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -