ImageFileSelector
sw926
91
Visit GitHub RepoImage Pickers

中文说明

ImageFileSelector

Use the system software to select, compress, crop images

Get it on Google Play

Build Status

support Android 4.0+

How to use

Maven

<dependency>
    <groupId>com.sw926.imagefileselector</groupId>
    <artifactId>library</artifactId>
    <version>1.0.10</version>
</dependency>

Gradle

compile 'com.sw926.imagefileselector:library:1.0.10'

Select Image

Init

ImageFileSelector mImageFileSelector = new ImageFileSelector(this);
mImageFileSelector.setCallback(new ImageFileSelector.Callback() {
    @Override
    public void onError(@NotNull ErrorResult errorResult) {
        switch (errorResult) {
            case permissionDenied:
                break;
            case canceled:
                break;
            case error:
                break;
        }
    }

    @Override
    public void onSuccess(@NotNull String file) {
    }
});

Add code to you Activity or Fragment

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mImageFileSelector.onActivityResult(this, requestCode, resultCode, data);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mImageFileSelector.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mImageFileSelector.onRestoreInstanceState(savedInstanceState);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    mImageFileSelector.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}

Setting parameters

// Set the output file size
mImageFileSelector.setOutPutImageSize(800, 600);
Set the picture save quality, 0 to 100
mImageFileSelector.setQuality(80);

Start select image

// take picture from camera
mImageFileSelector.takePhoto(this, requestCode);
// select image from sdcard
mImageFileSelector.selectImage(this, requestCode);
// Set the save path of the image,default: /sdcard/Android/data/{packagename}/cache/images/
mImageFileSelector.setOutPutPath();

Crop Image

Init

ImageCropper mImageCropper = new ImageCropper(this);
mImageCropper.setCallback(new ImageCropper.ImageCropperCallback() {
        @Override
        public void onError(@NotNull ImageCropper.CropperErrorResult result) {
            switch (result) {
                case error:
                    break;
                case canceled:
                    break;
                case notSupport:
                    break;
            }
        }

        @Override
        public void onSuccess(@NotNull String outputFile) {
        }
    });

Add code to you Activity or Fragment

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mImageCropper.onActivityResult(requestCode, resultCode, data);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mImageCropper.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mImageCropper.onRestoreInstanceState(savedInstanceState);
}

Setting parameters

// Sets the picture aspect ratio
mImageCropper.setOutPutAspect(1, 1);
// Sets the image size
mImageCropper.setOutPut(800, 800);
// Sets whether to scale
mImageCropper.setScale(true);

crop image

mImageCropper.cropImage(file);
Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT