kubatatami/RxImagePicker


Android. Pick image from camera or gallery using RxJava

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.kubatatami:RxImagePicker:'
	}
	dependencies {
		implementation("com.github.kubatatami:RxImagePicker:")
	}
	<dependency>
	    <groupId>com.github.kubatatami</groupId>
	    <artifactId>RxImagePicker</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.kubatatami" % "RxImagePicker" % ""
        
        

                            
    :dependencies [[com.github.kubatatami/RxImagePicker ""]]
        
        

Readme


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 >= 14.

In your build.gradle :

dependencies {
    compile 'com.mlsdev.rximagepicker:library:1.1.9'
    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.
                }
            });

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
            }
         });
RxImagePicker.with(this)                                                  
    .requestImage(Sources.GALLERY)                                        
    .flatMap(new Func1<Uri, Observable<? extends String>>() {             
        @Override                                                         
        public Observable<? extends String> call(Uri uri) {               
            return RxImageConverters.uriToFullPath(MainActivity.this, uri);
        }                                                                 
    })                                                                    
    .subscribe(new Action1<String>() {                                    
        @Override                                                         
        public void call(String path) {                                    
            // Do something with your image path
            // Ex. /storage/emulated/0/DCIM/Camera/20160701_113408.jpg                              
        }                                                                 
    });                                                                   

Sample App

<img src="https://cloud.githubusercontent.com/assets/1778155/11761109/cb70a420-a0bd-11e5-8cf1-e2b172745eab.png" width="400">

Authors

License

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

About MLSDev

<img src="https://cloud.githubusercontent.com/assets/1778155/11761239/ccfddf60-a0c2-11e5-8f2a-8573029ab09d.png" alt="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!