package com.mlsdev.rximagepicker;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class RxImageConverters {
    public static Observable<File> uriToFile(final Context context, final Uri uri, final File file) {
        return Observable.create(new Observable.OnSubscribe<File>() {
            @Override
            public void call(Subscriber<? super File> subscriber) {
                try {
                    InputStream inputStream = context.getContentResolver().openInputStream(uri);
                    copyInputStreamToFile(inputStream, file);
                    subscriber.onNext(file);
                } catch (Exception e) {
                    Log.e(RxImageConverters.class.getSimpleName(), "Error converting uri", e);
                    subscriber.onError(e);
                }
            }
        })
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());
    }

    private static void copyInputStreamToFile(InputStream in, File file) throws IOException {
        OutputStream out = new FileOutputStream(file);
        byte[] buf = new byte[10 * 1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.close();
        in.close();
    }

    public static Observable<Bitmap> uriToBitmap(final Context context, final Uri uri) {
        return Observable.create(new Observable.OnSubscribe<Bitmap>() {
            @Override
            public void call(Subscriber<? super Bitmap> subscriber) {
                try {
                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
                    subscriber.onNext(bitmap);
                } catch (IOException e) {
                    Log.e(RxImageConverters.class.getSimpleName(), "Error converting uri", e);
                    subscriber.onError(e);
                }
            }
        })
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());
    }
}

@@ -60,16 +60,48 @@
 ontext;%0A
+import android.database.Cursor;%0A
 import a
@@ -148,16 +148,47 @@
 et.Uri;%0A
+import android.os.Environment;%0A
 import a
@@ -2483,11 +2483,1839 @@
 );%0A    %7D
+%0A%0A    public static Observable%3CString%3E uriToFullUri(final Context context, final Uri originalUri) %7B%0A        return Observable%0A            .create(new Observable.OnSubscribe%3CString%3E() %7B%0A                @Override%0A                public void call(Subscriber%3C? super String%3E subscriber) %7B%0A                    Cursor imageCursor = null;%0A                    try %7B%0A                        String imageId = originalUri.getLastPathSegment().split(%22%253A%22)%5B0%5D.split(%22:%22)%5B1%5D;%0A                        final String%5B%5D imageColumns = %7BMediaStore.Images.Media.DATA%7D;%0A%0A                        Uri uri;%0A                        if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) %7B%0A                            uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;%0A                        %7D else %7B%0A                            uri = MediaStore.Images.Media.INTERNAL_CONTENT_URI;%0A                        %7D%0A%0A                        imageCursor = context.getContentResolver().query(uri, imageColumns, MediaStore.Images.Media._ID + %22=%22 + imageId, null, null);%0A                        if (imageCursor != null && imageCursor.moveToFirst()) %7B%0A                            subscriber.onNext(imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA)));%0A                        %7D else %7B%0A                            subscriber.onError(new Throwable(%22No image found%22));%0A                        %7D%0A                    %7D catch (Exception e) %7B%0A                        subscriber.onError(e);%0A                    %7D finally %7B%0A                        if (imageCursor != null) %7B%0A                            imageCursor.close();%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D)%0A            .subscribeOn(Schedulers.newThread())%0A            .observeOn(AndroidSchedulers.mainThread());%0A    %7D
 %0A%7D%0A

Add RxImageConverters.uriToFullUri