RedApparat / Fotoapparat

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

Is it possible to take picture with hidden CameraView? #265

Closed Yoda066 closed 6 years ago

Yoda066 commented 6 years ago

Hi. In our app, we would like to take pictures on background, without showing it to a user. I set CameraView visibility to GONE and INVISIBLE but then I wasn't able to get bitmapPhoto object.

PhotoResult photoResult = fotoaparat.takePicture();
 photoResult
                    .toBitmap()
                    .whenAvailable(bitmapPhoto -> {
                        File mypath = new File(directory, String.format("%s.jpeg", timestampValue));

                        FileOutputStream fos = null;
                        try {
                            fos = new FileOutputStream(mypath);
                            bitmapPhoto.bitmap.compress(Bitmap.CompressFormat.JPEG, 20, fos);
                            fos.close();
                        } catch (Exception e) {
                            Log.e("SAVE_IMAGE", e.getMessage(), e);
                        }
 return null;
                    });

I am guessing, you are making screenshot from CameraView when creating bitmap or something. So is there any workaround for this hidden picture taking I am looking for?

Thanks.

dmitry-zaitsev commented 6 years ago

We never tried that use case and we are not officially supporting it since Android P is supposed to block such camera usage.

What you can try to do is instead of hiding the view completely making it of a very small size or obstructing it by some other view with non-transparent background.