RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 408 forks source link

Photo Capture is taking too long time #100

Closed shivam2702 closed 7 years ago

shivam2702 commented 7 years ago
photoResult = fotoapparat.takePicture();
        photoResult
                .toBitmap()
                .whenAvailable(new PendingResult.Callback<BitmapPhoto>() {
                    @Override
                    public void onResult(BitmapPhoto result) {
                        selectedBitmap = rotateBitmap(result.bitmap, -result.rotationDegrees);
                        stopCamera();
                    }
                });
I/Choreographer:  Skipped 94 frames!  The application may be doing too much work on its main thread.
D/Fotoapparat: stopPreview
I/Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.

I am using version 1.3.0 Please let me know if I am doing anything wrong

dmitry-zaitsev commented 7 years ago

The reason why it takes a while is that you are rotating the image on the main thread. That is not a particularly fast operation, so consider moving it to a background thread.

One other (better) option would be to use Transformer:

photoResult
                .toBitmap()
                .transform(new Transformer<BitmapPhoto, Bitmap>() {
                    @Override
                    public Bitmap transform(BitmapPhoto input) {
                        return rotateBitmap(input.bitmap, -input.rotationDegrees);
                    }
                })
                .whenAvailable(new PendingResult.Callback<Bitmap>() {
                    @Override
                    public void onResult(Bitmap result) {
                        selectedBitmap = result;
                        stopCamera();
                    }
                });
shivam2702 commented 7 years ago

Thank's it saves time. but still it's taking approx 2 sec of time. Is it normal?

dmitry-zaitsev commented 7 years ago

Yes, that is expected. Most of the time goes into decoding Bitmap from JPEG byte array which camera sends to us. You can speed up the process by reducing the picture size in Fotoapparat initialization.