Giter Site home page Giter Site logo

livedataimagepicker's Introduction

LiveDataImagePicker

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

Setup

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

In your build.gradle :

dependencies {
    compile 'com.mlsdev.rximagepicker:library:2.1.5'    
}

Example

RxImagePicker.with(context).requestImage(Sources.CAMERA).subscribe(new Consumer<Uri>() {
                    @Override
                    public void accept(@NonNull Uri uri) throws Exception {
                        //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(getContext()).requestMultipleImages().subscribe(new Consumer<List<Uri>>() {
                    @Override
                    public void accept(@NonNull List<Uri> uris) throws Exception {
                        //Get images by uris.
                    }
                });

Using converters

RxImagePicker.with(context).requestImage(Sources.GALLERY)
    .flatMap(new Function<Uri, ObservableSource<Bitmap>>() {
                    @Override
                    public ObservableSource<Bitmap> apply(@NonNull Uri uri) throws Exception {
                        return RxImageConverters.uriToBitmap(getContext(), uri);
                    }
                }).subscribe(new Consumer<Bitmap>() {
                    @Override
                    public void accept(@NonNull Bitmap bitmap) throws Exception {
                        // Do something with Bitmap
                    }
                });
RxImagePicker.with(context).requestImage(Sources.GALLERY)
    .flatMap(new Function<Uri, ObservableSource<File>>() {
                    @Override
                    public ObservableSource<File> apply(@NonNull Uri uri) throws Exception {
                        return RxImageConverters.uriToFile(getContext(), uri, new File("YOUR FILE"));
                    }
                }).subscribe(new Consumer<File>() {
                    @Override
                    public void accept(@NonNull File file) throws Exception {
                        // Do something with your file copy
                    }
                });

About

LiveDataImagePicker is forked from [mlsdev]: https://github.com/MLSDev/RxImagePicker

livedataimagepicker's People

Contributors

frederikos avatar hamen avatar s0nerik avatar saadfarooq avatar shijilsmb avatar slavafir avatar stuartsoft avatar timusus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.