Giter Site home page Giter Site logo

imagepickerplus's Introduction

Image Picker+

Simple Photo Picker for Android. Supports jpeg, png, webp formats. Works on Android version 5 or higher.

Some functions:

✔️ Pick a picture from the gallery without storage permission.
✔️ Take a photo from the camera (camera permission is optional).
✔️ Rotate or crop the captured image.
✔️ Save the final image to the app's local directory so you can use it like a File, without a ContentResolver.
✔️ Transform result to Jpeg / PNG / WebP automatically if needed.

Why one more photo picker?

  1. Photopicker from Google is not good enough.
  2. Single entry point for camera/gallery images.
  3. Other libraries that I've tried have bugs and/or abandoned.

This library:

  1. Doesn't require Android 11 or Google Play services as the photopicker from Google does.
  2. Covers both gallery and camera sources of image.
  3. Has basic image editor (rotate / crop)

Why this library doesn't require storage permissions?

It doesn't have access to the file system of the device. The system component provides content to this lib instead.
See Intent.ACTION_OPEN_DOCUMENT for more details.

Why camera permission is optional?

It's vaguely mentioned in the documentation. Unless you declare the camera permission in your app's manifest, you don't need to ask for runtime permission for this library. If you declare the camera permission (for other features in your app), this lib will ask for runtime permission automatically.

How rotation / crop works?

Thanks to uCrop library

Usage

For example in your activity:

// You can use the modern way to receive the result like this. Or you can use onActivityResult().
private val launcher = registerForActivityResult(StartActivityForResult()) {
    it?.data?.data?.let { uri ->
        // Done. Use the received uri with captured image inside.
        imageView.setImageURI(uri)
    }
}

ImagePickerPlus
    .createIntent(
        activity = this,
        PickRequest(
            source = PickSource.GALLERY, // or PickSource.CAMERA
            transformation = ImageTransformation(
                maxSidePx = 1024, // Or -1 if limit isn't needed
                encodeToFormat = ImageFormat.JPEG, // Or null if transformation isn't needed
            ),
        )
    )
    .let { launcher.launch(it) }

Sample application:

picture

Setup:

  1. Add maven { url 'https://jitpack.io' } to the allprojects or dependencyResolutionManagement section in top-level build.gradle or settings.gradle.
    For example (settings.gradle):
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}
  1. Add implementation 'com.github.Andrew0000:ImagePickerPlus:$latest_version' to the module-level build.gradle

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

imagepickerplus's People

Contributors

andrew0000 avatar

Stargazers

Fantasy、ado avatar Emanuele avatar Abhinav avatar  avatar Yousef Behfar avatar  avatar HamidReza Mohammad Jafari avatar Denis Diakov avatar  avatar david avatar  avatar  avatar

Watchers

 avatar

imagepickerplus's Issues

Camera doesn't work on Samsung

Hi! I tested the camera functionality on the Samsung Galaxy A52 running Android 13 and encountered an issue. When attempting to take a photo, there was no confirmation button to return the result to the application, only a preview of the taken photo was available.

Option to choose only one crop mode.

Hello,
This is not an issue, but a possibile feature that could be widely used.

I am working an application that need final image to be scaled in 512x512 ( i.e. square with custome pixel value).

I could able to use this library though, but app will crash if user select some other crop option rather than square like 16:9, 4:3 5:4 etc.

I have working experience with uCrop earlier, and I knew that uCrop provides options to retrict the user to crop in any particular ratio.
I think, you guys doing good job to combine picker and cropper in a single frame.
Could you also consider this feature request?

TODO: Show informative error in case of cloud provider + no internet

Steps:

  • Switch internet off
  • Try to pick an image from Google Drive (which is not in the cache of Google Drive, i.e. not recently picked with internet)

Result:
Image isn't picked, nothing happens.
Log:

java.io.FileNotFoundException: StorageFileLoadException[connection_failure]
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:781)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2008)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1823)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1500)
at crocodile8.image_picker_plus.utils.FileUtils.copyUriContentToFile(FileUtils.kt:19)
at crocodile8.image_picker_plus.provider.GalleryProvider.onActivityResult(GalleryProvider.kt:36)

Expected:
Show an understandable error Toast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.