androidimagepicker

repository·master·Indexed 18 days ago

https://github.com/easonline/androidimagepicker

An Android library for selecting single or multiple images, taking photos via camera, and cropping images for avatars. It provides methods such as pickSingle(), pickMulti(), and pickAndCrop() to handle image selection and cropping workflows.

Tokens
1.3K
Snippets
4
Records
4
Agent score
14%

What's inside androidimagepicker

  1. Add imagePicker to your Gradle project

    master

    To use imagePicker, include the imagepickerModule project in your dependencies. You can also optionally include image loading libraries like Universal Image Loader, Glide, or Picasso to support your project's image handling needs.

    dependencies {
        compile project(':imagepickerModule')
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'  //optional
        compile 'com.github.bumptech.glide:glide:3.6.1'   //optional
        compile 'com.squareup.picasso:picasso:2.4.0'   //optional
    }
  2. Select and crop an image for an avatar

    master

    Use AndroidImagePicker.getInstance().pickAndCrop() to select an image and immediately open a cropping interface.

    Parameters:

    • Activity: The current activity context.
    • isShowCamera: Boolean to enable/disable camera access.
    • size: The target size for the crop (e.g., 120).

    The result is returned via OnImageCropCompleteListener, which provides the cropped Bitmap and the ratio used.

    //select and crop avatar
    AndroidImagePicker.getInstance().pickAndCrop(MainActivity.this, true, 120, new AndroidImagePicker.OnImageCropCompleteListener() {
                        @Override
                        public void onImageCropComplete(Bitmap bmp, float ratio) {
                            Log.i(TAG,"=====onImageCropComplete (get bitmap="+bmp.toString()+");
                            ivCrop.setVisibility(View.VISIBLE);
                            ivCrop.setImageBitmap(bmp);
                        }
                    });
  3. Pick a single image

    master

    Use AndroidImagePicker.getInstance().pickSingle() to allow a user to select one image. You can specify whether to show the camera via the isShowCamera boolean. Results are returned via the OnImagePickCompleteListener callback as a List<ImageItem>.

    //single select
    AndroidImagePicker.getInstance().pickSingle(MainActivity.this, isShowCamera, new AndroidImagePicker.OnImagePickCompleteListener() {
                        @Override
                        public void onImagePickComplete(List<ImageItem> items) {
                            if(items != null && items.size() > 0){
                                Log.i(TAG,"=====selected:"+items.get(0).path);
                                mAdapter.clear();
                                mAdapter.addAll(items);
                            }
                        }
                    });
  4. Pick multiple images

    master

    Use AndroidImagePicker.getInstance().pickMulti() to allow a user to select multiple images. Similar to single selection, you can enable the camera using isShowCamera. The callback onImagePickComplete provides a List<ImageItem> containing all selected items.

    //multi select
    AndroidImagePicker.getInstance().pickMulti(MainActivity.this, isShowCamera, new AndroidImagePicker.OnImagePickCompleteListener() {
                        @Override
                        public void onImagePickComplete(List<ImageItem> items) {
                            if(items != null && items.size() > 0){
                                Log.i(TAG,"=====selected:"+items.get(0).path);
                                mAdapter.clear();
                                mAdapter.addAll(items);
                            }
                        }
                    });