Git Product home page Git Product logo

android-image-cropper's Introduction

Android Image Cropper

build status Codacy Badge Android Arsenal Download

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

Crop

Usage

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

See GitHub Wiki for more info.

Include the library

compile 'com.theartofdev.edmodo:android-image-cropper:2.2.+'

Using Activity

  1. Add CropImageActivity into your AndroidManifest.xml
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"/>
  1. Start CropImageActivity using builder pattern from your activity
CropImage.activity(imageUri)
   .setGuidelines(CropImageView.Guidelines.ON)
   .start(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.setImageBitmap(bitmap);
// or
cropImageView.setImageUriAsync(uri);
  1. Get cropped image
Bitmap cropped = cropImageView.getCroppedImage();
// or (must subscribe to async event using cropImageView.setOnGetCroppedImageCompleteListener(listener))
cropImageView.getCroppedImageAsync();

Features

  • Built-in CropImageActivity.
  • Set cropping image as Bitmap, Resource or Android URI (Gallery, Camera, Dropbox, etc.).
  • Image rotation 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.
  • Bitmap memory optimization.
  • 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

2.2.5

  • Fix to webp file extension (thx Nathan)
  • Fix wrong initial crop window when image contains exif data.
  • Added corners to circular crop window, can be removed by setting BorderCornerThickness to 0.

2.2.3

  • Fix Android state restore overrides state set by client.

2.2.2

  • Fix rotation zooms and changes aspect ratio when fixed aspect ratio is used.

2.2.1

  • Fix listeners getting garbage collected bug (thx @TheFinestArtist)

2.2.0

  • Fix non-straight angle rotation handling.
  • Add activity counter-clockwise rotation button (configurable, hidden by default).
  • Add activity rotation degrees configuration (default 90)

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.

android-image-cropper's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.