ImagePicker

Easy to use and customizable library Choose a photo from the gallery or take a photo with the camera. You can also crop and compress the image according to the size, resolution and size of the image.

  • Select an image from the gallery
  • Select an image in Google Drive
  • Taking pictures with the camera
  • Image cropping (cropping the image to the specified aspect ratio or allowing the user to select one)
  • Image compression (compressing the image according to the specified resolution and size)
  • Restore the result of the image as a file, the file path as string or Uri object
  • Permission to use the camera and memory pen

Use of

  1. Gradle dependency:allprojects {
    repositories {
    jcenter() // For the ImagePicker library, this security is sufficient. Although it is also published on the jitpac
    maven { url https://jitpack.io } / Don’t forget to add your project for uCrop – internal library
    }
    }.

Implementation of com.github.Drjacky: ImagePicker: $libVersion.

Where

If you want to get the result of the activity in a modern way (Lambda), install the InlineActivityResult library :

Implementation of com.github.florent37:inline-activity-result-kotlin:1.0.4.

  1. If you are targeting Android 10 or later (targetSdkVersion >= 29), set requestLegacyExternalStorage to true in the manifest file of your :

  1. The ImagePicker configuration is created using the Builder template.

ImagePicker.with(this)
.crop() //Crop image (optional), Check adjustment for more options
.cropOval() //One circle in the dimmed layer
.compress(1024) //Final image size is less than 1 MB (optional)
.maxResultSize(1080, 1080) //Final image resolution is less than 1080 x 1080 (optional)
.start()

Java

ImagePicker.Companion.with(this)
.crop() //Crop image (optional), check customization for more options
.cropOval() //Fine darker image to have circle within
.compress(1024) //Final image size will be smaller than 1MB (optional)
.maxResultSize(1080, 1080) //Final image resolution will be smaller than 1080 x 1080 (optional)
.start()

  1. Treatment of resultsStandard method (preferred method)

Overwrite the OnActivityResult method and manage the result of the ImagePicker.

overwrite fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
//Image Uri becomes non-zero on RESULT_OK
fall fileUri = data ?.data
imgProfile.setImageURI(fileUri))

// You can get the File object with the intention of
trap file:File = ImagePicker.getFile(data) !!!!.

// You can also specify the path to the file from the intention
fall filePath:String = ImagePicker.getFilePath(data)!
} else if (resultCode == ImagePicker.RESULT_ERROR) {
Toast.makeText(dit, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(dit, cancelled task, Toast.LENGTH_SHORT).show()
}
}

Online method (with the InlineActivityResult library, only works with FragmentActivity and AppCompatActivity) (Not used with framing, see #32).

ImagePicker.with(this)
.compress(1024) //The final image size will be less than 1 MB (optional)
.maxResultSize(1080, 1080) //The final image resolution will be less than 1080 x 1080 (optional)
.start { resultCode, data ->
as (resultCode == Activity.RESULT_OK) {
//Image Uri will not be void on RESULT_OK
fall fileUri = data ?.data
imgProfile.setImageURI(fileUri)

// You can extract the File object from the expected file
val:File = ImagePicker.getFile(data).

// You can also change the file path of intention
trap filePath:String = ImagePicker.getFilePath(data)
} as (resultCode == ImagePicker.RESULTATEN_ERROR) {
Toast.makeText(context, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, Task Cancelled, Toast.LENGTH_SHORT).show()
}
}

Setting

  • Select an image with GalleryImagePicker.with(this)
    .galleryOnly() // User can only start one image from Gallery
    .start() // Default request code is ImagePicker.REQUEST_CODE.
  • Capturing an image with CameraImagePicker.with(this)
    .cameraOnly() // The user can only capture an image with camera
    .start().
  • Crop imageImagePicker.with(this)
    .crop() //Crop image and let the user choose the image size.
    .start()
  • Crop an image with a fixed aspect ratio
    .crop(16f, 9f) //Crop an image with an aspect ratio of 16:9
    .start()
  • Crop the square image (e.g. for the profile)ImagePicker.with(this)
    .cropSquare() //Cropping the square image, is identical to crop(1f, 1f)
    .start().
  • Compress the image size (e.g. the image should not be larger than 1 MB)ImagePicker.with(this)
    .compress(1024) //Final image size will be smaller than 1 MB
    .start()
  • Set the image resolutionImagePicker.with(this)
    .maxResultSize(620, 620) // The final image resolution will be less than 620 x 620
    .start().
  • Intercept ImageProvider, can be used for analysisImagePicker.with (this)
    .setImageProviderIntercept ImageProvider
    Log.d (ImagePicker, Selected ImageProvider : +imageProvider.name)
    }
    .start()
  • Specify the storage directory for captured, trimmed or compressed imagesImagePicker.with(this)
    // Check the path to the image storage directory
    .saveDir(File(Environment.getExternalStorageDirectory(), ImagePicker))
    // .saveDir(Environment.getExternalStorageDirectory()))
    // .saveDir(getExternalFilesDir(null) !!!!
    .start()
  • Limit MIME types by gallery imageImagePicker.with(this)
    .galleryMimeTypes( //Exclude gif images
    mimeTypes = arrayOf(
    image/png,
    image/jpg,
    image/jpeg
    )
    )
    .start()
  • You can also use the application code with ImagePickerImagePicker.with(this)
    .maxResultSize(620, 620)
    .start(101) //The application code is 101, you can use it in onActivityResult
  • Add the following settings to your color.xml file if you want to customize the uCrop activity.
    @color/[email protected]/teal_500

Compatibility

  • Library – Android Kitkat 4.4+ (API 19)
  • Example – Android Kitkat 4.4+ (API 19)

GitHub

keemstar house,idubbbz age,how tall is leafyishere,keemstar dollar in the woods,h3h3 net worth,keemstar h3h3,keemstar socialblade,dramaalert,h3h3 age,keemstar lawyer,scarce net worth,keemstar sub count,keemstar net worth 2020,keemstar warzone wednesday,keemstar height and weight,markiplier height,keemstar twitter,pewdiepie height,keemstar weight loss,keemstar age,daniel keem net worth,keemstar net worth,keemstar daughter,pewdiepie net worth,keemstar girlfriend

You May Also Like

Trump’s transition sabotage threatens vaccine rollout

Given the current state of emergency in the country, they have practical…

Man Utd boss Solskjaer regrets Donny van de Beek transfer, reckons Jamie Redknapp

Jamie Redknapp believes that Ole Gunnar Solskjaer regrets the transfer of Manchester…

What does the future of road racing look like during a pandemic?

Step, step, step. Sarah Hall could clearly hear her feet touching the…

NCAA gives UMass tennis a harsh lesson in power — over a phone jack

In January, following LSU’s 42-25 victory over Clemson in the National University…