Drjacky/ImagePicker
소개
📸Image Picker for Android, Pick images from Gallery or Capture a new image with Camera🖼
디자인 및 미디어What you can do
- Pick Gallery Images
- Pick Images from Google Drive
- Capture Camera Image
- Crop Images(Crop image based on provided aspect ratio or let user choose one)
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original📸Image Picker Library for Android
Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera. It also allows to Crop the Image based on Aspect Ratio, Resolution and Image Size.
🏍Features
- Pick Gallery Images
- Pick Images from Google Drive
- Capture Camera Image
- Crop Images(Crop image based on provided aspect ratio or let user choose one)
- Compress Images(Compress image based on provided resolution and size)
- Retrieve Image Result as File, File Path as String or Uri object
- Handle Runtime Permission for Camera and Storage
🎬Preview
| Profile Image Picker | Gallery Only | Camera Only |
|---|---|---|
![]() |
![]() |
![]() |
💻Usage
Gradle dependency:
allprojects {
repositories {
mavenCentral() // For ImagePicker library, this line is enough. Although, it has been published on jitpack as well
maven { url "https://jitpack.io" } //Make sure to add this in your project for uCrop - an internal library
}
}
implementation 'com.github.Drjacky:ImagePicker:$libVersion'
🎨Customization
If you want to get the activity result:
Kotlin
private val launcher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val uri = it.data?.data!!
// Use the uri to load the image
// Only if you are not using crop feature:
uri?.let { galleryUri ->
contentResolver.takePersistableUriPermission(
uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
)
}
//////////////
}
}
Java
ActivityResultLauncher<Intent> launcher=
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),(ActivityResult result)->{
if(result.getResultCode()==RESULT_OK){
Uri uri=result.getData().getData();
// Use the uri to load the image
}else if(result.getResultCode()==ImagePicker.RESULT_ERROR){
// Use ImagePicker.Companion.getError(result.getData()) to show an error
}
});
Both Camera and Gallery:
ImagePicker.with(this)
//...
.provider(ImageProvider.BOTH) //Or bothCameraGallery()
.createIntentFromDialog { launcher.launch(it) }
Crop image:
.crop()
Crop image with 16:9 aspect ratio:
.crop(16f, 9f)
Crop square image(e.g for profile):
.cropSquare() //Crop square image, its same as crop(1f, 1f)
Oval crop image:
.crop()
.cropOval() //Allow dimmed layer to have a circle inside
Set Max Width and Height of final image:
.maxResultSize(512, 512, true) //true: Keep Ratio
Java sample for using createIntentFromDialog:
ImagePicker.Companion.with(this)
.crop()
.cropOval()
.maxResultSize(512,512,true)
.provider(ImageProvider.BOTH) //Or bothCameraGallery()
.createIntentFromDialog((Function1)(new Function1(){
public Object invoke(Object var1){
this.invoke((Intent)var1);
return Unit.INSTANCE;
}
public final void invoke(@NotNull Intent it){
Intrinsics.checkNotNullParameter(it,"it");
launcher.launch(it);
}
}));
If you want just one option(camera or gallery):
launcher.launch(
ImagePicker.with(this)
//...
.cameraOnly() // or galleryOnly()
.createIntent()
)
Let the user to resize crop bounds:
.crop()
.cropFreeStyle()
Let the user to pick multiple files or single file in gallery mode:
.setMultipleAllowed(true)
Let the user defines the output format:
.setOutputFormat(Bitmap.CompressFormat.WEBP)
Intercept ImageProvider; could be used for analytics purposes:
ImagePicker.with(this)
.setImageProviderInterceptor { imageProvider -> //Intercept ImageProvider
Log.d("ImagePicker", "Selected ImageProvider: "+imageProvider.name)
}
.createIntent()
Intercept Dialog dismiss event:
ImagePicker.with(this)
.setDismissListener {
// Handle dismiss event
Log.d("ImagePicker", "onDismiss");
}
.createIntent()
Limit MIME types while choosing a gallery image:
.galleryMimeTypes( //Exclude gif images
mimeTypes = arrayOf(
"image/png",
"image/jpg",
"image/jpeg"
)
)
Add Following parameters in your colors.xml file, if you want to customize uCrop Activity:
<resources>
<!-- Here you can add color of your choice -->
<color name="ucrop_color_toolbar">@color/teal_500</color>
<color name="ucrop_color_statusbar">@color/teal_700</color>
<color name="ucrop_color_widget_active">@color/teal_500</color>
</resources>
💥Compatibility
- Library - Android Kitkat 4.4+ (API 19)
- Sample - Android Kitkat 4.4+ (API 19)
📃 Libraries Used
- uCrop https://github.com/Yalantis/uCrop
- Compressor https://github.com/zetbaitsu/Compressor
- ImagePicker https://github.com/Dhaval2404/ImagePicker which my work is based on this repository.
License
관련 프로젝트 살펴보기
불러오는 중…


