quanhua92 / AndroidUsbCamera

Use USB Webcam on non-rooted Android devices with UVCCamera library from saki4510t
Apache License 2.0
59 stars 31 forks source link

How to take photos and videos? #1

Closed jp1017 closed 8 years ago

jp1017 commented 8 years ago

Q: How to take photos and videos?

quanhua92 commented 8 years ago

Hi, You need to use IFrameCallback from com.serenegiant.usb.IFrameCallback; In onConnect method. add this line before camera.startPreview()

camera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_RGB565/*UVCCamera.PIXEL_FORMAT_NV21*/);

Then, you can receive each frame via ByteBuffer. In order to record videos, you much implement ourself.

    final Bitmap bitmap = Bitmap.createBitmap(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, Bitmap.Config.RGB_565);
    private final IFrameCallback mIFrameCallback = new IFrameCallback() {
        @Override
        public void onFrame(final ByteBuffer frame) {
            frame.clear();
            synchronized (bitmap) {
                bitmap.copyPixelsFromBuffer(frame);
            }
            mImageView.post(mUpdateImageTask);
        }
    };

    private final Runnable mUpdateImageTask = new Runnable() {
        @Override
        public void run() {
            synchronized (bitmap) {
                mImageView.setImageBitmap(bitmap);
            }
        }
    };
jp1017 commented 8 years ago

Thanks.