Open frank0123 opened 5 years ago
private final IFrameCallback callback = new IFrameCallback() { @override public void onFrame(final ByteBuffer frame) { new Thread(new Runnable() { byte[] bytes = new byte[frame.remaining()]; frame.get(bytes); if(bytes.length > 0) { int offset = frame.arrayOffset(); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, offset, bytes.length - offset); ...... } }).start(); } }
use createBitmap instead of decodeByteArray, I got this exception:
java.lang.RuntimeException: Buffer not large enough for pixels at android.graphics.Bitmap.copyPixelsFromBuffer
private final IFrameCallback callback = new IFrameCallback() { @override public void onFrame(final ByteBuffer frame) { new Thread(new Runnable() { Bitmap bitmap = Bitmap.createBitmap(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(frame); ...... }).start(); } }
PS: First, I applied this uvcCamera.setFrameCallback(frameCallback, UVCCamera.PIXEL_FORMAT_NV21);
uvcCamera.setFrameCallback(frameCallback, UVCCamera.PIXEL_FORMAT_NV21);
And, when I check this: if(frame.hasArray()) { }
if(frame.hasArray()) { }
it returns false!
use createBitmap instead of decodeByteArray, I got this exception: