ImageFileSelector
Use the system software to select, compress, crop images
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);