简体   繁体   中英

How I can capture video from Android Canvas without root?

I'm developing a painting app, with canvas and SurfaceView, and I want to record user operations, and generate video.

In this moment I'm trying:

public static Bitmap captureView(View v) {
    Log.v(CAPTURE_TAG, "init");
    v.setDrawingCacheEnabled(true);
    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    //v.destroyDrawingCache();
    v.setDrawingCacheEnabled(false); // clear drawing cache
    Log.v(CAPTURE_TAG, "Fin:");
    return b;
}

and I call this every 50ms, using timer, and AsynTask, on AsynkTask, on onPostExecute method I save the bitmap in external storage:

public class takeCaptureTask extends AsyncTask<View, Void, Bitmap> {

    @Override
    protected void onPostExecute(Bitmap result) {
        Log.v("taskCapt", "Fin - InitSave");
        new saveCaptureTask().execute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.v("taskCapt", "init");
    }

    @Override
    protected Bitmap doInBackground(View... params) {
        return Utils.captureView(params[0]);
    }
}

And finally generate video using NDK and ffmpeg.

My problem is the performance, using this, every screenshot take 200ms (5FPS), and I need at least 15 FPS.

My questions are:
1- I'm in the correct way to do the screen recording without root?
2- can I take screenshot of canvas using other methods?
3- It's posible take screenshots from NDK without root? in this case, how?
4- It's faster save data to External Storage using NDK?
5- How buffer a lot of images to process it later?

My appologies for my bad English.

Thanks a lot for your help!

This would depend on how you are drawing. You can actually using Bitmap and Canvas as a draw buffer, and that would be very easy to capture. There's so many ways to do this, including only do a screen cap if there was a change in the view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM