Friday, March 23, 2012

How to take screenshot of application and store it in SDCARD


How to take screenshot of application and store it in SDCARD

The first part is explained in this Tutorial, that is taking the screenshot of the application (View).
The second part is storing it in the SDCARD. This is possible by compressing the image bitmap to bytes and then store.
?
Drag and copy the code
01
02
03
04
05
06
07
08
09
10
11
12
13
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
 
        File f = new File(Environment.getExternalStorageDirectory()
                                + File.separator + "test.jpg");
        try {
           f.createNewFile();
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
       } catch (Exception e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
Finally dont forgot to put the following permission in the manifest file.
?
Drag and copy the code
1
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

No comments: