1

I want to take screen shot programmatically in android when camera is live on surface view, I have also inflated multiple layouts on over surface view but when I'm trying to take screen shot programmatically then screenshot has been taken but issue is stay there one that is screenshot is black view means my picture which is live on surface view that not appear in screen shot.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Can you frame your question properly? – Chaithanya Apr 16 '14 at 11:38
  • Yes, Actually i want to take screenshot programaticaly when camera is live on surface view. i take my picture from front-camera with screen shot not by camera intent. – user2983308 Apr 16 '14 at 11:43
  • AFAIK, you cannot capture a `SurfaceView` contents via any non-rooted mechanism. – CommonsWare Apr 16 '14 at 12:16
  • 1
    The fundamental problem is that, if you're handing the SurfaceView's Surface to Camera for preview, the frames from the camera are never present in the application process. They go straight from Camera (mediaserver) to the system compositor (surfaceflinger). If you capture to a SurfaceTexture and render that onto SurfaceView with GLES, you can get the pixels with `glReadPixels()`. – fadden Apr 16 '14 at 20:04
  • Possible duplicate of [Android Take Screenshot of Surface View Shows Black Screen](https://stackoverflow.com/questions/27817577/android-take-screenshot-of-surface-view-shows-black-screen) – Anjani Mittal Nov 22 '18 at 11:28

1 Answers1

1

Have you tried something like this:

Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream  os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();

Ofcourse, this works only if your device is rooted.

Read this: https://stackoverflow.com/a/14718588/1374065

Community
  • 1
  • 1
vanste25
  • 1,754
  • 14
  • 39
  • 1
    This works on rooted phone only... Also post from where you get this – Viswanath Lekshmanan Apr 16 '14 at 11:49
  • 1
    I needed something like this in my project, so i have made a service which takes screenshots. I think that i have found this here: http://stackoverflow.com/questions/16741302/how-to-take-a-screenshots. Also, i think that you cannot take a screenshot of a surface. http://stackoverflow.com/questions/12724237/taking-screen-shot-of-a-surfaceview-in-android – vanste25 Apr 16 '14 at 11:53
  • Sir, this not working because my device is not routed. – user2983308 Apr 16 '14 at 11:59
  • Okay, i mentioned that at the bottom of the post. You are trying to take a screenshot of a SurfaceView? If so, read this http://stackoverflow.com/questions/12724237/taking-screen-shot-of-a-surfaceview-in-android – vanste25 Apr 16 '14 at 12:08