Android Image Cropper
Image Cropping Library for Android, optimized for Camera / Gallery.
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
Include the library
Add permissions to manifest
Using Activity
- Add CropImageActivity into your AndroidManifest.xml «`xml
- Override onActivityResult method in your activity to get crop result
Using View
- Add CropImageView into your activity «`xml
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 10.
- 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
- Adding option to omit camera intents on getPickImageChooserIntent (thx Hugo Rossi)
- Portuguese Language localization (thx Hugo Rossi)
- Removed saving bitmap into parcel in onSaveInstanceState to prevent TransactionTooLargeException
- By default nothing will happen and the view will be restored empty (if cropping image loaded using bitmap).
- Added config SaveBitmapToInstanceState to enable saving bitmap to temp file so it can be restored (default is false because of possible performance implications).
- Always prefer using URI to load image from cropping!
- Fix restore state not restoring rotation.
- Fix initial crop window may be in invalid position because reading previous image instance state.
- Fix instance state saved before any image loaded resulted in corrupted initial crop rectangle.
- Fix corners of crop overlay offset for oval shape resulting in confusing UI (#256).
- Fix support for negative rotation values for CropImageActivity.
- Add start method that accepts android.app.Fragment , annotated with @RequiresApi 11
- Super simple crop activity quick start flow that handles URI and permissions (huge thanks to @adwiv)
- Add image horizontal/vertical flipping during cropping (huge thanks to @tibbi).
- Handle OOM error for cropping set bitmap object, previously only image set by URI handled OOM.
- Allows for rotation degrees to be negative, fixes operator-precedence-related bug in flipAxes computation (thx Tim Cooke)
- Added crop overlay released listener (thx Richard Yee)
- Added originalUri and originalBitmap to CropResult object.
- Fix resetCropRect() resetting image rotation to 0 instead of the original exif data.
- Fix ignoring image rotation data in setImageBitmap(Bitmap, ExifInterface ) method.
- Removed deprecated listeners.
- Fix image picker for xiaomi and huawei phones (thx @nicolabeghin)
- Fix crop window get corrupted on CropImageView resize.
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:
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.
Android-Image-Cropper is maintained by ArthurHub. This page was generated by GitHub Pages.
Источник
Android java crop image
Android Image Cropper
Powerful (Zoom, Rotation, Multi-Source), customizable (Shape, Limits, Style), optimized (Async, Sampling, Matrix) and simple image cropping library for Android.
For a working implementation, please have a look at the Sample Project
Add permissions to manifest
Add this line to your Proguard config file
- Add CropImageActivity into your AndroidManifest.xml
- Start CropImageActivity using builder pattern from your activity
- Override onActivityResult method in your activity to get crop result
- Add CropImageView into your activity
- 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..
- 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.
- Fix crash on Android O (thx @juliooa)
- Update to support library to AndroidX (thx @mradzinski)
- Handle failure when selecting non image file (thx @uncledoc)
- More translations (thx @jkwiecien, @david-serrano)
- Update gradle wrapper to 4.4
- Update support library to 27.1.1 and set is statically! (thx @androideveloper)
- Fix NPE in activity creation by tools (thx @unverbraucht)
- More translations (thx @gwharvey, @dlackty, @JairoGeek, @shaymargolis)
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:
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.
About
Image Cropping Library for Android, optimized for Camera / Gallery.
Источник
Android java crop image
Wanna help the project? Amazing!
Android Image Cropper
Powerful (Zoom, Rotation, Multi-Source); Customizable (Shape, Limits, Style); Optimized (Async, Sampling, Matrix); Simple image cropping library for Android.
Add to your project
Step 1. Add the JitPack repository to your root build.gradle
Step 2. Add the dependency
Step 3. Add permissions to manifest
Only need if you run on devices under OS10 (SDK 29)
Step 4. Set source compatibility version to Java 11
The library is up to date with the latest releases, if you are not using Java 11 yet please check the release page for previous working versions.
Go to app level build.gradle file
Add this line inside android in build.gradle
This expects Gradle 7.0+
Using the Library
There is 3 ways of using the library:
- Calling crop directly (Sample code: sample/crop_image )
- Using the CropView (Sample code: sample/crop_image_view )
- Extending the activity (Sample code: sample/extend_activity ) Your choice depends on how you want your layout to look.
Obs: The library has a public pick image contract, more on wiki.
Calling crop directly
- Register for activity result with CropImageContract
- Add CropImageView into your activity
Extend to make a custom activity
If you want to extend the CropImageActivity please be aware you will need to setup your CropImageView You can check a sample code in this project com.canhub.cropper.sample.extend_activity.app.SExtendActivity
- Add CropImageActivity into your AndroidManifest.xml
- Setup your CropImageView after call super.onCreate(savedInstanceState)
Custom dialog for image source pick
When calling crop directly the library will prompt a dialog for the user choose between gallery or camera (If you keep both enable). We use the Android default AlertDialog for this. If you wanna customised it with your app theme you need to override the method showImageSourceDialog(..) when extending the activity (above)
- 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..
- Cropping window shape: Rectangular, Oval (square/circle by fixing aspect ratio), as well as rectangular modes which only allow vertical or horizontal cropping.
- Cropping window aspect ratio: Free, 1:1, 4:3, 16:9 or Custom.
- Guidelines appearance: Off / Always On / Show on Touch.
- Cropping window Border line, border corner and guidelines thickness and color.
- Cropping background color.
For more information, see the GitHub Wiki.
Forked from ArthurHub 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:
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.
About
Image Cropping Library for Android, optimised for Camera / Gallery.
Источник
Android java crop image
uCrop — Image Cropping Library for Android
This project aims to provide an ultimate and flexible image cropping experience. Made in Yalantis
For a working implementation, please have a look at the Sample Project — sample
Include the library as local library project.
implementation ‘com.github.yalantis:ucrop:2.2.6’ — lightweight general solution
implementation ‘com.github.yalantis:ucrop:2.2.6-native’ — get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)
Add UCropActivity into your AndroidManifest.xml
The uCrop configuration is created using the builder pattern.
Override onActivityResult method and handle uCrop result.
You may want to add this to your PROGUARD config:
If you want to let your users choose crop ratio dynamically, just do not call withAspectRatio(x, y) .
uCrop builder class has method withOptions(UCrop.Options options) which extends library configurations.
Currently you can change:
- image compression format (e.g. PNG, JPEG, WEBP), compression
- image compression quality [0 — 100]. PNG which is lossless, will ignore the quality setting.
- whether all gestures are enabled simultaneously
- maximum size for Bitmap that is decoded from source Uri and used within crop view. If you want to override default behaviour.
- toggle whether to show crop frame/guidelines
- setup color/width/count of crop frame/rows/columns
- choose whether you want rectangle or oval crop area
- the UI colors (Toolbar, StatusBar, active widget state)
- and more.
- Library — Android ICS 4.0+ (API 14) (Android GINGERBREAD 2.3+ (API 10) for versions = 2.1.2)
- Fixed #584
- Fixed #598
- Fixed #543
- Fixed #602
- And other improvements
- AndroidX migration
- Redesign
- Several fixes including #550
- Several fixes including #445, #465 and more!
- Material design support
- uCrop fragment as child fragment
- Added Italian language
- Several fixes including #121, #173, #184 and more!
- New APIs introduced #149, #186 and #156
- Fixes issue with EXIF data (images taken on front camera with Samsung devices mostly) #130#111
- Added API to set custom set of aspect ratio options for user. #131
- Added API to set all configs via UCrop.Options class. #126
- Added ABI x86_64 support. #105
- Native image crop (able to crop high-resolution images, e.g. 16MP & 32MP images on Nexus 5X).
- WebP compression format is not supported at the moment (choose JPEG or PNG).
- Now library copies EXIF data to cropped image (size and orientation are updated).
- Introduced «Freestyle» crop (you can resize crop rectangle by dragging it corners) #32
- Now image & crop view paddings are not associated #68
- Updated API
- Introduced http(s) Uri support!
- Image is cropped in background thread.
- Showing loader while Bitmap is processed (both loading and cropping).
- Several bug fixes.
- Couple new things to configure.
- Updated minSdkVersion to Android ICS 4.0 (no reason to support couple percents of old phones).
Image is loaded in background thread. Better error-handling for image decoding.
Improved EXIF data support (rotation and mirror).
Small UI updates.
Couple new things to configure.
Sample updated with possibility to choose custom aspect ratio.
Источник