GithubHelp home page GithubHelp logo

pistolcaffe / android-image-cropper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from canhub/android-image-cropper

0.0 0.0 0.0 11.89 MB

Image Cropping Library for Android, optimised for Camera / Gallery.

Home Page: https://canhub.github.io/

License: Apache License 2.0

Kotlin 100.00%

android-image-cropper's Introduction

CanHub

โ˜•Using the library in Java

โ“FAQ - frequently asked question

Android Image Cropper

  • Powerful (Zoom, Rotation, Multi-Source);
  • Customizable (Shape, Limits, Style);
  • Optimized (Async, Sampling, Matrix);
  • Simple image cropping library for Android.

Features List

Crop

Add to your project

Step 1. Add the JitPack repository to your root build.gradle

  allprojects {
     repositories {
       ....
       maven { url 'https://jitpack.io' }
     }
  }

Step 2. Add the dependency

  dependencies {
       implementation 'com.github.CanHub:Android-Image-Cropper:${version}'
  }

Latest Release Version

Step 3. Add permissions to manifest

Only need if you run on devices under OS10 (SDK 29)

<manifest>
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
       android:maxSdkVersion="28" />
</manifest>

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
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_11
         targetCompatibility JavaVersion.VERSION_11
     }
    
     kotlinOptions {
         jvmTarget = JavaVersion.VERSION_11.toString()
     }
  • This expects Gradle 7.0+

Using the Library

There is 3 ways of using the library:

Your choice depends on how you want your layout to look.

Calling crop directly

Sample code

  • Register for activity result with CropImageContract
class MainActivity {
   private val cropImage = registerForActivityResult(CropImageContract()) { result ->
           if (result.isSuccessful) {
               // use the returned uri
               val uriContent = result.uriContent 
               val uriFilePath = result.getUriFilePath(context) // optional usage
           } else {
               // an error occurred
               val exception = result.error
           }
       }

   private fun startCrop() {
       // start picker to get image for cropping and then use the image in cropping activity
       cropImage.launch(
           options {
               setGuidelines(Guidelines.ON)
           }
       )

       //start picker to get image for cropping from only gallery and then use the image in
       //cropping activity
       cropImage.launch(
           options {
               setImagePickerContractOptions(
                   PickImageContractOptions(includeGallery = true, includeCamera = false)
               )
           }
       )

       // start cropping activity for pre-acquired image saved on the device and customize settings
       cropImage.launch(
           options(uri = imageUri) {
               setGuidelines(Guidelines.ON)
               setOutputCompressFormat(CompressFormat.PNG)
           }
       )
   }
}

Posts

Wanna help the project? Amazing!

License

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:

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

Contributors

canato avatar vanniktech avatar chriscoomber avatar alireza-farahani avatar devenom1 avatar ravindu1024 avatar sanjaydevtech avatar bhagyae5308 avatar androiddeveloperlb avatar clouddjr avatar armchilingarov avatar ashique-perumbavoor avatar fadsel avatar gwharvey avatar happyfacade avatar zikstar avatar morons avatar junaediwidjojo avatar connyduck avatar loukwn avatar lazydevpro avatar manuelrego27 avatar scana avatar mouwrice avatar nowdev avatar crocsandcoffee avatar ondree avatar paulwoitaschek avatar pratyaksh1610 avatar remimabsout avatar

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.