A simple library to select images from the gallery and camera.
There are many libraries out there. May be some serves your purposes but not satisfactory. This library is different from the others.
Why should you use it?
- CameraX library to capture images.
- It also uses UCrop library to crop images.
- It uses best compression to compress your image without loosing image's quality.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.shaon2016:ProPicker:1.0.5'
}
Add this in your build.gradle app module
android {
//.........
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
The simplest way to start
ProPicker.with(this)
.start { resultCode, data ->
if (resultCode == RESULT_OK && data != null) {
val list = ProPicker.getSelectedPickerDatas(data)
if (list.size > 0) {
iv.setImageURI(list[0].uri)
}
}
}
What you can do with ImagePicker
Camera
ProPicker.with(this)
.cameraOnly()
.crop()
.start { resultCode, data ->
if (resultCode == RESULT_OK && data != null) {
val picker = ProPicker.getPickerData(data)
iv.setImageURI(picker?.uri)
}
}
Gallery
ProPicker.with(this)
.galleryOnly()
.start { resultCode, data ->
if (resultCode == RESULT_OK && data != null) {
val list = ProPicker.getSelectedPickerDatas(data)
if (list.size > 0) {
Glide.with(this)
.load(list[0].file)
.into(iv)
}
}
}
- cameraOnly() -> To open the CameraX only
- crop() -> Only works with camera
- compressImage -> compresing image work for both gallery and camera
- galleryOnly() -> To open the gallery view only
- singleSelection -> Pick single file
- multiSelection -> Pick multi file and get the result as ArrayList
- maxResultSize -> Max Width and Height of final image
- compressImage -> compresing image work for both gallery and camera
- compressVideo -> (Under Development)
- onlyImage -> Select image from gallery
- onlyVideo -> Select video from gallery
- ProPicker.getPickerDataAsByteArray(this, intent) -> Returns all the data as ByteArray
- ProPicker.getSelectedPickerDatas(intent: Intent) -> Get all the data
- ProPicker.getPickerData(intent: Intent) -> Get single data