0

I am trying to create a screenshot capturing app in android which capture screen shot of device screen by using adb command programmatically. I have tried every link from stack overflow and other sites but not much successful yet. can any body help me out here. I have followed this link Android take screenshot on rooted device to create the .raw file but now i am stuck on how to convert raw file to image in android.

Community
  • 1
  • 1
Furqan Ali
  • 137
  • 2
  • 13

2 Answers2

1

if raw is image file then u can change extentention to jpg or png,

File ss = new File(ssDir, "ss.raw");

change this to

   File ss = new File(ssDir, "ss.jpg");

but capturing screenshots require root permission to execute su permission

 File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "screeshot.jpg");
Process localProcess  = Runtime.getRuntime().exec("su");
OutputStream  os = localProcess .getOutputStream();
 //DataOutputStream  dos = (DataOutputStream) localProcess.getOutputStream();
os.write(("/system/bin/screencap -p " + f.toString()).getBytes("ASCII"));
//dos.writeBytes("exit\n");
os.flush();
os.close();
localProcess .waitFor();
Sumit
  • 1,022
  • 13
  • 19
  • os.writeBytes does not exist in OutputStream and my device has the root permissions butt this code just save black image and nothing else it just creates the image n ot get the screen shot and create it and simply changing the extension can also simply creates image because i am using this command /dev/graphics/fb0 to save framebuffer in raw form and then i need code or library which converts raw byte file to image file – Furqan Ali Sep 25 '14 at 09:36
  • 1
    this code works perfect on my kitkat but i don't know about you check your logcat issue and must add read write externel storage permission in manifest – Sumit Sep 25 '14 at 09:59
  • I am testing this code on Android 2.3.5 but i will let you know if it works – Furqan Ali Sep 25 '14 at 10:20
  • By the way i have added android.permission.WRITE_EXTERNAL_STORAGE butt which Read permissions are needed – Furqan Ali Sep 25 '14 at 10:30
  • Well that did not work either on my Android device. I just know if there is way to convert raw file to image. – Furqan Ali Sep 25 '14 at 10:50
  • if your device is rooted then open file manager go to system then bin then check there 'screencap' file exist??. btw i have tested it on 4.4.2 – Sumit Sep 26 '14 at 03:51
  • Thanks for your help but I have captured the image using frame buffer fb0 command – Furqan Ali Sep 27 '14 at 07:10
1

Android cannot do that by itself. You need a external decoder. There are libraries which can decode, demosaicing, whitebalance etc and convert to RGB. This is a digital negative and needs a lot of image processing before its viewable in Android.

Check out dcraw, its a library for decoding all types of RAW-files.

CheChe
  • 26
  • 3