Add Gradle dependency:
implementation 'com.github.gabrielbb:cutout:0.1.2'
Start the CutOut screen with this single line:
CutOut.activity().start(this);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == CutOut.CUTOUT_ACTIVITY_REQUEST_CODE) {
switch (resultCode) {
case Activity.RESULT_OK:
Uri imageUri = CutOut.getUri(data);
// Save the image using the returned Uri here
break;
case CutOut.CUTOUT_ACTIVITY_RESULT_ERROR_CODE:
Exception ex = CutOut.getError(data);
break;
default:
System.out.print("User cancelled the CutOut screen");
}
}
}
You can use one or more options from these:
CutOut.activity()
.src(uri)
.bordered()
.noCrop()
.intro()
.saveType(CutOutSaveTypes.SAVE_TO_STORAGE)
.start(this);
By default the user can select images from camera or gallery but you can also pass an android.net.Uri
of an image that is already saved:
Uri uri = Uri.parse("/images/cat.jpg");
CutOut.activity().src(uri).start(this);
CutOut.activity().bordered().start(this);
This option makes the final PNG have a border around it. The default border color is White. You can also pass the android.graphics.Color
of your choice.
CutOut.activity().noCrop().start(this);
By default and thanks to this library: Android-Image-Cropper, the user can crop or rotate the image. This option disables that cropping screen.
CutOut.activity().intro().start(this);
Display an intro explaining every button usage. The user can skip the intro and it is only shown once. The images displayed in the intro are the same you saw in the "Features" section of this document.
0.1.2
- Removed Admob Ads automatic integration. I will probably add it later. For now, it was causing problems.
- Images are now saved as temporary files in the cache directory. This guarantees that these images will be deleted when users uninstall your app or when the disk memory is low. If you want the images to live forever on the Gallery, you should take the returned Uri and save the image there by yourself.
Copyright (c) 2018 Gabriel Basilio Brito
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1 - You cannot use this software to make an Android app that its main goal is to remove background from images and publish it to the Google Play Store, but you can use it to integrate the functionality in an existing app or a new app that does more than just this.
2 - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.