Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android screenshot using Opencv

How do I make a screenshot using Opencv (android) and convert it to an Image. I myself have made a code for screenshot see link here. The output of this image is black which is not I wanted. Is there also a possibility of using a mat here?

public void camera_b(View v)
{
    String path = Environment.getExternalStorageDirectory().toString() + "/" + "hellp.jpg";

    v = getWindow().getDecorView().getRootView();
    v.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    OutputStream out = null;
    File imageFile = new File(path);

    try {
        out = new FileOutputStream(imageFile);
        // choose JPEG format
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
        out.flush();
    } catch (FileNotFoundException e) {
        // manage exception
    } catch (IOException e) {
        // manage exception
    } finally {

        try {
            if (out != null) {
                out.close();
            }

        } catch (Exception exc) {
        }

    }
}