RedApparat / Fotoapparat

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

Shoot the photos and start the preview again very slowly #88

Closed xiaolongyuan closed 6 years ago

xiaolongyuan commented 7 years ago
    private Observable<String> takePictureObservable() {

        String savePath = Environment.getExternalStoragePublicDirectory
                (Environment
                        .DIRECTORY_DCIM) + "/CAMERA/";

        File dir = new File(savePath);
        if (!dir.exists()) {
            dir.mkdir();
        }

        final String path = savePath + "IMG_" + new Date().getTime() + ".jpg";
        final File file = new File(path);
        final PhotoResult photoResult = fotoapparat.takePicture();
        return Observable
                .create(new Observable.OnSubscribe<String>() {
                    @Override
                    public void call(final Subscriber<? super String> subscriber) {

                        Logger.i("此时线程:"+Thread.currentThread().getName());
                        photoResult.saveToFile(file)
                                .whenAvailable(new PendingResult.Callback<Void>() {
                                    @Override
                                    public void onResult(Void aVoid) {
                                        Logger.i("whenAvailable线程:"+Thread.currentThread().getName());
                                        subscriber.onNext(path);
                                        subscriber.onCompleted();
                                    }
                                });
                        ;
                    }
                })
                .subscribeOn(Schedulers.io())
                ;
    }

It takes 8-10 seconds to start previewing

faketon commented 7 years ago

i think image is big. i use big image some device is slow and some device is normal. are you try photoSize(smallestSize).

dmitry-zaitsev commented 6 years ago

There is nothing we can do about that - that fully depends on capabilities of the device.

By the way, for using Fotoapparat with RxJava consider using our adapters: https://github.com/Fotoapparat/Fotoapparat/tree/master/fotoapparat-adapters