Giter Site home page Giter Site logo

colourmoon / image-picker Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 0.0 243 KB

This is Library exclusively useful for the image selection from the camera or gallery. Developed by ColourMoon

Home Page: https://thecolourmoon.com

License: MIT License

Kotlin 100.00%
android-library colourmoon image image-crop image-cropper image-picker image-picker-android image-picker-library

image-picker's Introduction

Image Picker Library : Simplified Image Handling for Android Developers

Are you an Android developer struggling with the intricacies of image selection, cropping, and rotation within your app? The image-picker library is here to simplify your image handling tasks and provide a seamless experience for your users. This versatile library offers the following features:

  1. Streamlined Image Selection: Tired of complex code for capturing images from the camera or selecting from the gallery? The image-picker library allows you to effortlessly integrate image selection capabilities in your app. Bid farewell to tedious coding and concentrate on building a delightful user experience.

  2. Intuitive Cropping: Cropping images often involves intricate calculations and user interactions. With the library's built-in cropping functionality, you can enable users to crop images intuitively. Whether it's refining a profile picture or selecting the perfect image dimensions, the library simplifies the process.

  3. Image Rotation Made Easy: Correcting image orientation after capture can be a pain point. Our library seamlessly handles image rotation, ensuring your users always see their images correctly aligned. Say goodbye to rotated selfies and landscape images that don't display correctly!

  4. Configuration Flexibility: Customizing the image selection experience is crucial. With the image-picker library, you can tailor settings to your app's requirements. Whether it's allowing only gallery or camera access, enabling crop and compression, or setting up a camera-only mode, the library provides flexible configuration options.

  5. Real-time Image Handling: The library streamlines the process of receiving and processing selected images. With a dedicated ResultImage callback, you can easily retrieve the image path and file, facilitating seamless real-time handling and manipulation.

  6. Robust Error Handling: The library includes comprehensive error handling to ensure smooth user interactions. If an issue arises during the image selection process, error handling mechanisms are in place to inform users gracefully.

  7. Compressed Images: Image size can impact app performance and user experience. With built-in compression options.

  8. User-friendly Design: The library's user interface is designed to be intuitive and user-friendly. Users can navigate image selection, cropping, and other processes with ease, enhancing their interaction with your app.

Say goodbye to the complexities of image handling and make the development process smoother with the image-picker library. Empower your app with seamless image selection, cropping, and rotation, and provide your users with a delightful experience they'll appreciate.

Integrate the image-picker library into your project using the provided setup instructions and let it revolutionize your image handling challenges. If you encounter any issues or have questions, our support team is here to assist you on this journey to simpler, more efficient image handling.

Step 1. Add the JitPack repository to your build file

Add the following code to your build.gradle file at the project level:

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

Step 2. Add the dependency

In your app-level build.gradle file, add the dependency for the image-picker library:

dependencies {
    implementation 'com.github.colourmoon:image-picker:$VersonName'
}

Replace $VersonName with the actual version you want to use, for example:

implementation 'com.github.colourmoon:image-picker:v1.0.3'

Step 3. Implement ResultImage in your Activity/Fragment and Call CMImagePicker

In your activity or fragment, follow these steps to integrate and use the CMImagePicker:

import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.colourmoon.imagepicker.CMImagePicker
import com.colourmoon.imagepicker.ResultImage
import java.io.File

class MainActivity : AppCompatActivity() {
    private lateinit var imageView: ImageView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val imagePicker = CMImagePicker(this, launcher)
        imagePicker
            .allowCrop(false)
            .allowCompress(true)
            .allowGalleryOnly(false)
            .allowCameraOnly(false)
            .start()
    }

    private val launcher = object : ResultImage {
        override val result: ActivityResultLauncher<Intent> = registerForActivityResult(
            ActivityResultContracts.StartActivityForResult()
        ) { result: ActivityResult ->
            if (result.resultCode == Activity.RESULT_OK) {
                val imagePath = result.data?.getStringExtra(RESULT_IMAGE_PATH)
                val imageFile: File? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                    result.data?.getSerializableExtra(
                        RESULT_IMAGE_FILE, File::class.java
                    )
                } else {
                    result.data?.getSerializableExtra(RESULT_IMAGE_FILE) as File
                }

                // Handle the image path and image file here
                // Make sure to check for null and file existence before using them
                // doSomeOperations()
            }
        }
    }
}

Configuration and descriotion Along with Comment

val imagePicker = CMImagePicker(this, launcher)
imagePicker
    .allowCrop(false) // Enable or disable cropping (default: false)
    .allowCompress(true) // Enable compression (default: false)
    .allowGalleryOnly(false) // Allow only gallery selection (default: both camera and gallery)
    .allowCameraOnly(false) // Allow only camera usage (default: both camera and gallery)
    .start() // Launch the image picker

Result Image Callback:

private val launcher = object : ResultImage {
    override val result: ActivityResultLauncher<Intent> = registerForActivityResult(
        ActivityResultContracts.StartActivityForResult()
    ) { result: ActivityResult ->
        if (result.resultCode == Activity.RESULT_OK) {
            // Retrieve image path and file
            val imagePath = result.data?.getStringExtra(RESULT_IMAGE_PATH)
            val imageFile = result.data?.getSerializableExtra(RESULT_IMAGE_FILE) as File?
            
            // Handle the image path and file
            // ...
        }
    }
}

With these steps, you should be able to successfully integrate and use the Image Picker Library library in your project. If you encounter any issues or have further questions, feel free to reach out.

Contributing

Contributions to Image Picker Library are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

Image Picker Library is released under the MIT License. See the LICENSE file for more details.

Support

For any questions or support related to Image Picker Library, you can reach out to us at [email protected], [email protected] or join our community forum.

Credits

The Image Picker Library library was developed by Ronil Gwalani

image-picker's People

Contributors

pushpendracolourmoon avatar ronilgwalnai avatar

Stargazers

 avatar  avatar  avatar

image-picker's Issues

Android 9 or below, the camera does not work properly

Issue Description:

When working on Android 9 or below, the camera does not work properly. It takes time to initialize, and sometimes it only displays a black screen. Additionally, when we click on capture, the loader keeps loading indefinitely.

Calling:

  imagePicker
            .allowCrop(false)
            .allowCompress(true, 80)
            .allowGalleryOnly(false)
            .allowCameraOnly(true)
            .start()

Logs:

getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
17:23:12.957  D  getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
17:23:12.961  D  Resolved dynamic range for use case androidx.camera.core.Preview-d84b7d05-7c44-48dd-9669-cd32da2863d0 to no compatible HDR
                 dynamic ranges.
                 DynamicRange@4f4abb8{encoding=UNSPECIFIED, bitDepth=0}
                 ->
                 DynamicRange@2994e1b{encoding=SDR, bitDepth=8}
17:23:12.965  D  getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
17:23:12.965  D  Surface created[total_surfaces=1, used_surfaces=0](androidx.camera.core.processing.SurfaceEdge$SettableSurface@b43ce60}
17:23:12.966  D  Surface created[total_surfaces=2, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@f87708c}
17:23:12.967  D  New surface in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@f87708c}
17:23:12.967  D  use count+1, useCount=1 androidx.camera.core.SurfaceRequest$2@f87708c
17:23:12.968  D  getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
17:23:12.970  D  createPipeline(cameraId: 0, streamSpec: StreamSpec{resolution=1280x960, dynamicRange=DynamicRange@2994e1b{encoding=SDR, bitDepth=8}, expectedFrameRateRange=[0, 0], implementationOptions=androidx.camera.camera2.impl.Camera2ImplConfig@a810978})
17:23:12.972  D  Surface created[total_surfaces=3, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@4a3c851}
17:23:12.983  D  {Camera@462271f[id=0]} Use case androidx.camera.core.ImageCapture-399fd3eb-8049-4d40-9378-60c5597582b4166587933 ACTIVE
17:23:12.983  D  Active and attached use case: [] for camera: 0
17:23:12.985  D  {Camera@462271f[id=0]} Use case androidx.camera.core.Preview-d84b7d05-7c44-48dd-9669-cd32da2863d0165689076 ACTIVE
17:23:12.985  D  Active and attached use case: [] for camera: 0
17:23:12.988  D  {Camera@462271f[id=0]} Use case androidx.camera.core.ImageCapture-399fd3eb-8049-4d40-9378-60c5597582b4166587933 ACTIVE
17:23:12.988  D  Active and attached use case: [] for camera: 0
17:23:12.988  D  Active and attached use case: [] for camera: 0
17:23:12.989  D  {Camera@462271f[id=0]} Use cases
                 [androidx.camera.core.Preview-d84b7d05-7c44-48dd-9669-cd32da2863d0165689076, androidx.camera.core.ImageCapture-399fd3eb-8049-4d40-9378-60c5597582b4166587933] now
                 ATTACHED
17:23:12.990  D  All use
                 case: [androidx.camera.core.ImageCapture-399fd3eb-8049-4d40-9378-60c5597582b4166587933, androidx.camera.core.Preview-d84b7d05-7c44-48dd-9669-cd32da2863d0165689076] for
                 camera: 0
17:23:12.990  D  mMeteringRepeating is ATTACHED, SessionConfig Surfaces: 2, CaptureConfig Surfaces: 1
17:23:12.991  D  Active and attached use
                 case: [androidx.camera.core.ImageCapture-399fd3eb-8049-4d40-9378-60c5597582b4166587933, androidx.camera.core.Preview-d84b7d05-7c44-48dd-9669-cd32da2863d0165689076] for
                 camera: 0
17:23:12.999  D  {Camera@462271f[id=0]} Resetting Capture Session
17:23:13.001  D  {Camera@462271f[id=0]} Releasing session in state INITIALIZED
17:23:13.004  D  {Camera@462271f[id=0]} Attempting to force open the camera.
17:23:13.005  D  tryOpenCamera(Camera@462271f[id=0]) [Available Cameras: 1, Already Open: false (Previous state: CLOSED)] --> SUCCESS
17:23:13.005  D  Recalculating open cameras:
                 Camera                                       State                 
                 -------------------------------------------------------------------
                 Camera@5b23396[id=1]                         UNKNOWN               
                 Camera@462271f[id=0]                         OPENING               
                 -------------------------------------------------------------------
                 Open count: 1 (Max allowed: 1)

Please investigate and resolve this issue.

https://imgur.com/n93ch5w

Image Description

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.