Android Image Cropper


Source link: https://github.com/ArthurHub/Android-Image-Cropper

Android Image Cropper

Powerful (Zoom, Rotation, Multi-Source), customizable (Shape, Limits, Style), optimized (Async, Sampling, Matrix) and simple image cropping library for Android.

Usage

For a working implementation, please have a look at the Sample Project

See GitHub Wiki for more info.

  1. Include the library
compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+' 

Add permissions to manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

Using Activity

  1. Add CropImageActivity into your AndroidManifest.xml
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat"/> <!-- optional (needed if default theme has no action bar) -->
  1. Start CropImageActivity using builder pattern from your activity
// start picker to get image for cropping and then use the image in cropping activity CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.start(this);
  // start cropping activity for pre-acquired image saved on the device CropImage.activity(imageUri)  .start(this);
  // for fragment (DO NOT use `getActivity()`) CropImage.activity()
.start(getContext(), this);
  1. Override onActivityResult method in your activity to get crop result
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {

  CropImage.ActivityResult result = CropImage.getActivityResult(data);

  if (resultCode == RESULT_OK) {

 Uri resultUri = result.getUri();

  
}
 else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

 Exception error = result.getError();

  
}

}
 
}

Using View

  1. Add CropImageView into your activity
<!-- Image Cropper fill the remaining available height --> <com.theartofdev.edmodo.cropper.CropImageView
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/cropImageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
  1. Set image to crop
cropImageView.setImageUriAsync(uri);
 // or (prefer using uri for performance and better user experience) cropImageView.setImageBitmap(bitmap);
  1. Get cropped image
// subscribe to async event using cropImageView.setOnCropImageCompleteListener(listener) cropImageView.getCroppedImageAsync();
 // or Bitmap cropped = cropImageView.getCroppedImage();

Features

  • Built-in CropImageActivity.
  • Set cropping image as Bitmap, Resource or Android URI (Gallery, Camera, Dropbox, etc.).
  • Image rotation/flipping during cropping.
  • Auto zoom-in/out to relevant cropping area.
  • Auto rotate bitmap by image Exif data.
  • Set result image min/max limits in pixels.
  • Set initial crop window size/location.
  • Request cropped image resize to specific size.
  • Bitmap memory optimization, OOM handling (should never occur)!
  • API Level 14.
  • More..

Customizations

  • Cropping window shape: Rectangular or Oval (cube/circle by fixing aspect ratio).
  • Cropping window aspect ratio: Free, 1:1, 4:3, 16:9 or Custom.
  • Guidelines appearance: Off / Always On / Show on Toch.
  • Cropping window Border line, border corner and guidelines thickness and color.
  • Cropping background color.

For more information, see the GitHub Wiki.

Posts

Change log

2.5.1 (in-dev)

  • Try solve manifest merger issue by adding transitive flag #405 (thx @j-garin)
  • Use thread pool executors for async image loading and cropping operations to prevent app hang if default executor is busy (thx @ruifcardoso)
  • Fix image rotation breaking min/max crop result restrictions #401
  • Propagate all extra data set on start crop activity intent back in crop result intent #352

2.5.0

  • Update to sdk v26
  • Update gradle plugin to 2.0
  • Update min sdk version to 14
  • Fix NPE in getWholeImageRect
  • Remove crop_image_menu_crop drawable support, replace with setCropMenuCropButtonIcon builder api.
  • Support setting crop button title via builder api.
  • Add string resource for "no permissions" toast.

2.4.7

  • Fix toolbar menu crop icon sometimes appears with random icon (#305)
  • Use CharSequence instead of string for activity title (thx @KentHawkings) (#297)
  • Fix class not found exception on some Samsung devices (Huge thanks to @Vantablack) (#332)
  • Add original image dimensions to CropResult (Thanks @gazialankus) (#327)
  • Making the library JitPack-friendly (Thanks @gazialankus) (#325)
  • Allow a Fragment to call the startPickImageActivity help method in CropImage (Thanks @cdavietei) (#315)

See full change log.

License

Originally forked from edmodo/cropper.

Copyright 2016, Arthur Teplitzki, 2013, Edmodo, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

A library to help android developer working easly with activities and fragments

An Android library to build form and form validations easily.

Simple multiview adapter for RecyclerView written on Kotlin.

This library helps you to know when the app is in background or not, and if the app is in foreground, you can send the notification to your activity!

Its a Date Range Picker View with animation and improved UI.

Show case card view.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes