Android library to choose image from gallery or camera with option to compress result image

Overview

ImagePicker Downloads

Android library to choose image from gallery or camera with option to compress result image.

Download Android Arsenal

Add this to your project's build.gradle

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

And add this to your module's build.gradle

dependencies {
	implementation 'com.github.maayyaannkk:ImagePicker:x.y.z'
}

change x.y.z to version in

Usage

For full example, please refer to app module

No need to request for write external storage permission, library will do that.

Crop with 1:1 aspect ratio

Start image picker activity

The simplest way to start is setup options and start the activity. Set the FLAG_CROP to crop resulting image in 1:1 aspect ratio

Intent intent = new Intent(this, ImageSelectActivity.class);
intent.putExtra(ImageSelectActivity.FLAG_COMPRESS, false);//default is true
intent.putExtra(ImageSelectActivity.FLAG_CAMERA, true);//default is true
intent.putExtra(ImageSelectActivity.FLAG_GALLERY, true);//default is true
intent.putExtra(ImageSelectActivity.FLAG_CROP, isCrop);//default is false
startActivityForResult(intent, 1213);

Receive result

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1213 && resultCode == Activity.RESULT_OK) {
            String filePath = data.getStringExtra(ImageSelectActivity.RESULT_FILE_PATH);
            Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
            imageView.setImageBitmap(selectedImage);
        }
    }

Corner cases

throws IllegalStateException if:
-chooseFromCamera and chooseFromGallery both are false

Comments
  • If the user selects invalid data using your library, our app crashes

    If the user selects invalid data using your library, our app crashes

    Hi there, thanks for making a great library!

    But.... using your library in an app I tried to select an image from Google Drive - and the library crashed and made the whole app crash because I accidentally selected a text file instead of an image.

    Here is the stack trace:

    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:353)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:1001)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:968)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:918)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
        at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.compressImage(ImageCompression.java:96)
        at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.doInBackground(ImageCompression.java:45)
        at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.doInBackground(ImageCompression.java:18)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at java.lang.Thread.run(Thread.java:764) 
    

    This is using implementation 'com.github.maayyaannkk:ImagePicker:1.0.1'

    opened by nordfalk 4
  • Getting crash in android 10

    Getting crash in android 10

    in.mayanknagwanshi.imagepicker.ImageSelectActivity}: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.indiatalent.provider at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3520) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3659) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2245) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:227) at android.app.ActivityThread.main(ActivityThread.java:7835) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) Caused by: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.indiatalent.provider at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606) at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579) at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417) at in.mayanknagwanshi.imagepicker.imagePicker.ImagePicker.getCaptureImageOutputUri(ImagePicker.java:150) at in.mayanknagwanshi.imagepicker.imagePicker.ImagePicker.getPickImageChooserIntent(ImagePicker.java:93) at in.mayanknagwanshi.imagepicker.imagePicker.ImagePicker.start(ImagePicker.java:76) at in.mayanknagwanshi.imagepicker.ImageSelectActivity.onCreate(ImageSelectActivity.java:46) at android.app.Activity.performCreate(Activity.java:7974) at android.app.Activity.performCreate(Activity.java:7963) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3495) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3659)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2245)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:227)  at android.app.ActivityThread.main(ActivityThread.java:7835)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) 

    opened by pankajjangid 3
  • Can't select 2 pictures, it overwrites the images since the output image is stored with name

    Can't select 2 pictures, it overwrites the images since the output image is stored with name

    I checked the decompiled files and found that the output file is stored with a static name "profile.png". I had to implement the whole logic myself. After few hours of research, i was able to find a solution and i will be happy to collaborate if needed.

    opened by akshittyagi205 3
  • Fatal Exception while getting image from camera

    Fatal Exception while getting image from camera

    I select camera. Take an image but when I accept (click Ok), the app crushes.

    Looking at the logs I see this:

    java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:300) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:933) at android.graphics.Bitmap.createBitmap(Bitmap.java:912) at android.graphics.Bitmap.createBitmap(Bitmap.java:879) at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.compressImage(ImageCompression.java:96) at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.doInBackground(ImageCompression.java:45) at in.mayanknagwanshi.imagepicker.imageCompression.ImageCompression.doInBackground(ImageCompression.java:18) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  at java.lang.Thread.run(Thread.java:818) 

    opened by nyandika 3
  • Not working in Android 11

    Not working in Android 11

    Hello @maayyaannkk

    when i click button for the image with your library, this error is occur, the android version is 11 (Api 30). how can we solve this issue, i already update the library with latest version 1.0.10

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.royalways.montecarloretail/in.mayanknagwanshi.imagepicker.ImageSelectActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1 at java.util.ArrayList.get(ArrayList.java:439) at in.mayanknagwanshi.imagepicker.imagePicker.ImagePickerUtil.getPickImageChooserIntent(ImagePickerUtil.java:61) at in.mayanknagwanshi.imagepicker.ImageSelectActivity.onCreate(ImageSelectActivity.java:98) at android.app.Activity.performCreate(Activity.java:8000) at android.app.Activity.performCreate(Activity.java:7984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:223)  at android.app.ActivityThread.main(ActivityThread.java:7656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

    opened by rajam1215 2
  • Your library doesent work with support library fragments

    Your library doesent work with support library fragments

    In your demo app and other places you use android.app.Fragment For example in https://github.com/maayyaannkk/ImagePicker/blob/master/app/src/main/java/in/mayanknagwanshi/imagepicker/demo/fragment/ExampleFragment.java

    Please change that to using support fragments. That's what evryone uses

    opened by nordfalk 2
  • Not working in fragment

    Not working in fragment

    Hello Mayank,

    Hope you are doing well, I found that using your library and example it does not work in the fragment, it did not receive in fragment onActivityResult method.

    opened by ContextGrid 1
  • Some Error while merging manifest

    Some Error while merging manifest

    Merging Errors: Error: Attribute provider#android.support.v4.content.FileProvider@authorities value=(example.company.exam.provider) from AndroidManifest.xml:17:13-60 is also present at AndroidManifest.xml:14:13-80 value=(example.company.exam.easyphotopicker.fileprovider). Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:15:9-23:20 to override. app main manifest (this file), line 16 Error: Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/provider_paths) from AndroidManifest.xml:22:17-55 is also present at AndroidManifest.xml:19:17-50 value=(@xml/filepaths). Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml to override. app main manifest (this file), line 21

    opened by savadmv 1
  • Can't Open GPS Camera App from this Library

    Can't Open GPS Camera App from this Library

    I am using your library for take photo in my app. I want to use GPS Camera to take photo. While it try to take photo, there are no option to choose GPS Camera to take photo. Library take default camera to take photo.

    Please help me to solve this issue.

    opened by banyanandroid 1
  • support for minimum sdk less than 19

    support for minimum sdk less than 19

    Hi, I have been using this lib for Image selection , fro while. It works just fine until I decide to change my minimum sdk supported to be 17 instead of 19, then I started to face some merging issues ,

    the Error was ERROR: Manifest merger failed : uses-sdk:minSdkVersion 17 cannot be smaller than version 19 declared in library [com.github.maayyaannkk:ImagePicker:1.0.3] C:\Users\AltkamulSD-5\.gradle\caches\transforms-2\files-2.1\abd6a294f274c02798cd71c3e0758d70\jetified-ImagePicker-1.0.3\AndroidManifest.xml as the library might be using APIs not available in 17 Suggestion: use a compatible library with a minSdk of at most 17, or increase this project's minSdk version to at least 19, or use tools:overrideLibrary="in.mayanknagwanshi.imagepicker" to force usage (may lead to runtime failures) I think this is because that your minimum supported sdk is 19. can you change this please, so the minimum sdk is inherited from the project sdk. to avoid this issue. I mean if that is possible.

    opened by wdelawed 0
  • New logo/icon proposal

    New logo/icon proposal

    Good day sir. I am a graphic designer and i am interested in designing a logo for your good project. I will be doing it as a gift for free. I just need your permission first before I begin my design. Hoping for your positive feedback. Thanks

    enhancement 
    opened by mansya 4
Releases(1.0.13)
Owner
Mayank Nagwanshi
Got hooked to coding since my first 'Hello world' program and know stuff about Android development.
Mayank Nagwanshi
An Android App that uses Machine Learning to recognize the objects in an image captured from the phone's camera

Camera App ?? Description An Android App that uses Machine Learning (ML) to recognize the objects in an image captured from the phone's camera. • Allo

Shikeya Anderson 1 Dec 31, 2022
A new camera app for GrapheneOS based on the modern CameraX library.

This is the new GrapheneOS Camera app based on Android's modern CameraX library. It's currently in the alpha phase and isn't yet included in GrapheneO

GrapheneOS 513 Jan 1, 2023
Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.

LandscapeVideoCamera Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to

Jeroen Mols 1.2k Nov 22, 2022
Wrapper around the android Camera class that simplifies its usage

EasyCamera Wrapper around the android Camera class that simplifies its usage (read more about the process) Usage: // the surface where the preview wil

Bozhidar Bozhanov 642 Nov 27, 2022
📸 Use Android camera to take pictures and videos, based on `camera2` api.

Camera Use Android camera to take pictures and videos, based on camera2 api. Features Auto filled CameraView for previewing Support both image capture

Hong Duan 119 Nov 25, 2022
Android camera and serial communication utility that interacts with another device via a USB connection.

PVIT-Payload-Source Android camera and serial communication utility that interacts with another device via a USB connection. PVIT = Palos Verdes Insti

Zeroz & Onez 1 Nov 10, 2021
NguyenThienAn06105 - This repository consist of the code to read camera data on ESP8266 and a simple Android application to visualize the …

MLX90640-HeatCamera This repository consist of the code to read camera data on ESP8266 and a simple Android application to visualize the result. There

Christian Hein 0 Jan 1, 2022
Measures human heart rate using camera and flash light.

Heart-Rate-Ometer Introduction Measures human heart rate using camera and flash light. How-it-works https://github.com/phishman3579/android-heart-rate

Jan Rabe 81 Jun 29, 2022
Quick photo and video camera with a flash, customizable resolution and no ads.

Simple Camera A camera with flash, zoom and no ads. The camera is usable for both photo taking and video recording. You can switch between front and r

Simple Mobile Tools 644 Jan 7, 2023
Pix is a Whatsapp image picker replica. with this, you can integrate an image picker just like WhatsApp.

Pix (WhatsApp Style Image and Video Picker) Pix is a WhatsApp image picker replica. with this you can integrate a image picker just like WhatsApp. Upc

Akshay sharma 742 Jan 4, 2023
Image Picker library for Android

Ronnie-Image-Picker Asks for Camera and storage permission and return uri of the images taken or picked from the gallery. Min Api Level: 16 Build Syst

Ronnie Otieno 33 Nov 19, 2022
Instagram like Image Picker for Android

ImagePicker A simple Instagram like library to select images from the gallery and camera. Screenshot Usage For full example, please refer to the sampl

Akvelon 21 Sep 28, 2022
Android application to preview, record (MediaRecorder), and fetch each image from both front and rear cameras simultaneously

DuoCamera ?? Overview Android application to preview, record (MediaRecorder) and fetch each image from both front and rear cameras simultaneously. The

Igor Lashkov 5 Nov 28, 2022
Snappy - an android camerax library for taking snapshot fast & simple

Snappy is an android camerax library for taking snapshot fast & simple. Easy to integrate, 100% Kotlin & jetpack compose driven.

Nils Druyen 16 Dec 15, 2022
A library to take picture easy, transform your data in different format and save photos in your device

A Magic library to take photos and select pictures in Android. In a simple way and if you need it also save the pictures in device, and facial recogni

Fabian Rosales (Frosquivel Developer) 331 Nov 20, 2022
📸 A library that allows you to capture images secretly, in background without alerting users.

HiddenCamera A library that allows you to capture images secretly, in background without alerting users. Gradle Dependency Add the dependency to your

Cotta & Cush Limited 116 Dec 29, 2022
Bootcamp - Digital Innovation One e NTT Data - Aula de Recursos Nativos do Android

Recursos-Nativos-Android -Foto e Camera Bootcamp - Digital Innovation One e NTT Data - Aula de Recursos Nativos do Android Tutorial de uso da bibliote

Anne Nicolle Zimmermann 0 Jan 3, 2022
Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera.

Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera.

Simform Solutions 201 Jan 5, 2023
An Android Image compress library, reduce's the size of the image by 90% without losing any of its pixels.

Image Compressor An Android image compress library, image compressor, is small and effective. With very little or no image quality degradation, a comp

Vinod Baste 11 Dec 23, 2022