/RxImagePicker

Android. Pick image from camera or gallery using RxJava

Primary LanguageJavaMIT LicenseMIT

RxImagePicker

An easy way to get image from Gallery or Camera with request runtime permission on Android M using RxJava

Setup

To use this library your minSdkVersion must be >= 16.

In your build.gradle :

dependencies {
    compile 'com.mlsdev.rximagepicker:library:1.3.1'
    compile 'io.reactivex:rxjava:1.0.14'
}

Example

RxImagePicker.with(context).requestImage(Sources.CAMERA).subscribe(new Action1<Uri>() {
                @Override
                public void call(Uri uri) {
                    //Get image by uri using one of image loading libraries. I use Glide in sample app.
                }
            });

Request multiple images on Android Api level 18+ :

RxImagePicker.with(context).requestMultipleImages().subscribe(new Action1<List<Uri>>() {
            @Override
            public void call(List<Uri> uris) {
                //Get images by uris.
            }
        });

Using converters

RxImagePicker.with(context).requestImage(Sources.GALLERY)
    .flatMap(new Func1<Uri, Observable<Bitmap>>() {
             @Override
             public Observable<Bitmap> call(Uri uri) {
                 return RxImageConverters.uriToBitmap(context, uri);
             }
         })
         .subscribe(new Action1<Bitmap>() {
            @Override
            public void call(Bitmap bitmap) {
                // Do something with Bitmap
            }
         });
RxImagePicker.with(context).requestImage(Sources.GALLERY)
    .flatMap(new Func1<Uri, Observable<File>>() {
             @Override
             public Observable<File> call(Uri uri) {
                 return RxImageConverters.uriToFile(context, uri, new File("YOUR FILE"));
             }
         })
         .subscribe(new Action1<File>() {
            @Override
            public void call(File file) {
                // Do something with your file copy
            }
         });

Sample App

Authors

License

RxImagePicker is released under the MIT license. See LICENSE for details.

About MLSDev

MLSDev.com

RxImagePicker is maintained by MLSDev, Inc. We specialize in providing all-in-one solution in mobile and web development. Our team follows Lean principles and works according to agile methodologies to deliver the best results reducing the budget for development and its timeline.

Find out more here and don't hesitate to contact us!