Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

callBack to modify the bitmaps before saving them #261

@Lakedaemon

Description

@Lakedaemon

Could we please have a callback allowing us to modify bitmaps before saving them to the device ?
It can be done by passing an interface and hacking the following method in Spoon

private static void takeScreenshot(File file, final Activity activity, final Callback callback) throws IOException {
    View view = activity.getWindow().getDecorView();
    final Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
    if(Looper.myLooper() == Looper.getMainLooper()) {
        drawDecorViewToBitmap(activity, bitmap);
    } else {
        final CountDownLatch fos = new CountDownLatch(1);
        activity.runOnUiThread(new Runnable() {
            public void run() {
                try {
                    Spoon2.drawDecorViewToBitmap(activity, bitmap);
                } finally {
                    fos.countDown();
                }

            }
        });

        try {
            fos.await();
        } catch (InterruptedException var10) {
            String msg = "Unable to get screenshot " + file.getAbsolutePath();
            Log.e("Spoon", msg, var10);
            throw new RuntimeException(msg, var10);
        }
    }

    callback.peek(bitmap);  // user modifications there

    BufferedOutputStream fos1 = null;

    try {
        fos1 = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(CompressFormat.PNG, 100, fos1);
        Chmod.chmodPlusR(file);
    } finally {
        bitmap.recycle();
        if(fos1 != null) {
            fos1.close();
        }

    }

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions