Get screenshot of surfaceView in Android -


in application have view buttons , surfaceview. must take screenshot of view, in place of surfaceview black field. try solutions found on stackoverflow, don't work me.

this code usualy take screenshots:

file folder = new file(environment.getexternalstoragedirectory().getpath() + "/folder"); if (!folder.exists()) {     folder.mkdir(); } string path = folder.getabsolutepath() + "snapshot.png"; file file = new file(path); file.createnewfile();  view view = this.findviewbyid(android.r.id.content).getrootview(); view.setdrawingcacheenabled(true); bitmap drawingcache = view.getdrawingcache(); bitmap bitmap = bitmap.createbitmap(drawingcache);  fileoutputstream fos = null; try {     fos = new fileoutputstream(file);     bitmap.compress(compressformat.png, 100, fos); } {     bitmap.recycle();     view.setdrawingcacheenabled(false);     if (fos != null) {         try {             fos.close();         } catch (ioexception e) {             log.e(tag, e.getmessage(), e);         }     } } 

maybe can help.

i found solution how make screenshot (but don't know if correct use). in surfaceview created method drawbitmap:

public bitmap drawbitmap() {     bitmap bitmap = bitmap.createbitmap(getwidth(), getheight(), bitmap.config.argb_8888);     canvas canvas = new canvas(bitmap);     thread.dodraw(canvas);     return bitmap; } 

in next step compress bitmap:

 fileoutputstream fos = null; try {     fos = new fileoutputstream(file);     bitmap.compress(compressformat.png, 100, fos); } {     bitmap.recycle();     if (fos != null) {         try {             fos.close();         } catch (ioexception e) {             log.e(tag, e.getmessage(), e);         }     } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -