0

I am new to android development so I think this may be a teething issue on my part, but I am currently trying to use the PixelCopy function in android studio. I have code as shown below, and it matches what the base class is expecting although it is returning an error. Would anyone be able to assist me with this issue?

The code I currently have is as follows:

final HandlerThread handlerThread = new HandlerThread("PixelCopier");
handlerThread.start();

SurfaceView current = new SurfaceView(view.getContext());
PixelCopy.OnPixelCopyFinishedListener copyResult;

// Make the request to copy.
PixelCopy.request(current, bitmap, copyResult, handlerThread);

if (copyResult. == PixelCopy.SUCCESS) {
//If successful do tasks in here
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
M.Walker
  • 33
  • 8

1 Answers1

0

Try crating extracting finish listener as shown below in class.

private static void onPixelCopyFinished(int result) {
    if (result != PixelCopy.SUCCESS) {
        Log.e("err", "errMsg");
        return;
    }
}

You can pass the listener as below and also you'll also need to wrap it in try catch as it might throw an exception.

try {
        PixelCopy.request(current, bitmap, <YOUR CLASS>::onPixelCopyFinished, this.getHandler());
    } catch (IllegalArgumentException e) {
                // PixelCopy may throw IllegalArgumentException, make sure to handle it
        e.printStackTrace();
    }