Replacement for deprecated official Android crop image function

Related tags

ImageView cropimage
Overview

The MIT License (MIT)

Copyright (c) 2012 Jan Muller

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

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.

Cropimage

  • Added support for building with Gradle
  • Replacement for deprecated official Android crop image function
  • 2.2 API

  • Easy to integrate to your app.
  • Enjoy ;-)

Call this method to run CropImage activity

private void runCropImage() {

    // create explicit intent
    Intent intent = new Intent(this, CropImage.class);
    
    // tell CropImage activity to look for image to crop 
    String filePath = ...;
    intent.putExtra(CropImage.IMAGE_PATH, filePath);
    
    // allow CropImage activity to rescale image
    intent.putExtra(CropImage.SCALE, true);
    
    // if the aspect ratio is fixed to ratio 3/2
    intent.putExtra(CropImage.ASPECT_X, 3);
    intent.putExtra(CropImage.ASPECT_Y, 2);
    
    // start activity CropImage with certain request code and listen
    // for result
    startActivityForResult(intent, REQUEST_CODE_CROP_IMAGE);
}

Waiting for result

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode != RESULT_OK) {

        return;
    }  

    switch (requestCode) {

        case REQUEST_CODE_CROP_IMAGE:

            String path = data.getStringExtra(CropImage.IMAGE_PATH);
            
            // if nothing received
            if (path == null) {

                return;
            }

            // cropped bitmap
            Bitmap bitmap = BitmapFactory.decodeFile(mFileTemp.getPath());
            
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

Building with Gradle

To build with gradle, make sure you have installed the gradle wrapper in the top level directory. On my computer this is typically done (from the root of this project) with a:

cp -Rv /opt/android-studio/sdk/tools/templates/gradle/wrapper/* .

Make sure to adjust the path to whereever you installed Android Studio.

After doing this, to build issue the following command (again from the root of this project):

./gradlew assembleDebug

To install the example a running emulator or device, do a:

adb install -r ./simple-crop-image-example/build/apk/simple-crop-image-example-debug-unaligned.apk
Comments
  • Source code

    Source code

    Can anyone send me the whole code with R.java for android and all in zip file. I am not able to run between two classes, main to CropImage.java. Thanks a lot.

    opened by Dev2022 3
  • Project doesn't compile

    Project doesn't compile

    There are few things missing and the project doesn't compile.

    In the CropImage class

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
            mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
    

    There is no code HONEYCOMB and LAYER_TYPE_SOFTWARE

    also in Util class in int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); there is no getRotation() method

    opened by aprilapps 2
  • Added intent extra for pre-rotating the image

    Added intent extra for pre-rotating the image

    Added an addition intent extra for the crop view which can be used to pre-rotate the image before it is displayed. This is very useful, for example, when displaying a photo taken in portrait mode as the photo EXIF data can be read and used to correctly orient the image for cropping (see #16).

    opened by blork 0
  • Allow for hardware acceleration of rectangular crop...

    Allow for hardware acceleration of rectangular crop...

    I found the sluggishness of software rendering to be annoying so I made a fix to allow for hardware rendering (only of the rectangular crop, the circle crop still requires software rendering due to its use of clipPath).

    opened by kriserickson 0
  • Build issue

    Build issue

    Error:Could not find com.android.tools.build:gradle:2.2.2. Searched in the following locations: https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.2/gradle-2.2.2.jar Required by: 2way:simple-crop-image-lib:unspecified

    opened by gazalkochar 0
  • Cropped image does not get set in imageview in Galaxy s6

    Cropped image does not get set in imageview in Galaxy s6

    Right after selecting the image from gallery, the cropping class is getting called. After selecting the portion in the image to crop and tapping crop nothing happens. This happens only in samsung devies, especially Galaxy S6 and S6 edge. Please help. Below is the code i am using to call the CropImage class. Intent intent = new Intent(context, CropImage.class); intent.putExtra(CropImage.IMAGE_PATH, path); intent.putExtra(CropImage.SCALE, true); intent.putExtra(CropImage.ASPECT_X, 2); intent.putExtra(CropImage.ASPECT_Y, 2); getActivity().startActivityForResult(intent, PIC_CROP);

    Has someone face similar issues?

    opened by DavidRajPaul 1
  • Regarding crop tool

    Regarding crop tool

    here i try to crop image but its crop tool selection done only in square. can we select crop area also only from horizontal or vertical side. means not on only square?

    opened by sagarchavda 0
Owner
Jan Muller
Jan Muller
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 657 Jan 5, 2023
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 658 Dec 1, 2022
Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻

BigImageViewer Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling

Piasy 3.9k Dec 30, 2022
Image Picker with Customizable UI for Android, Pick an image from Gallery

Image Picker A Image Picker Library for Android (Supports Android 12) with fully

null 2 May 29, 2022
Slider-Gallery-Zoom: image slider for android supporting indicator and auto scroll with clicking on image

image slider supporting indicator and auto scroll with clicking on image to open full screen image slider swipe and pinch zoom gestures like gallery,just pass your images and the position of the current image.

Mahmoud Elian 3 May 28, 2022
Android library to generate image avatar from the first letter of a username. Letter avatar like Gmail Android best practice

AvatarImageGenerator Generate first letter avatar Image like gmail's contact avatar. It generates an drawable that can be be set to an ImageView. Inst

Korir Amos 61 Sep 25, 2022
Android widget for cropping and rotating an image.

Cropper The Cropper is an image cropping tool. It provides a way to set an image in XML and programmatically, and displays a resizable crop window on

Edmodo 2.9k Nov 14, 2022
Custom ImageView for moving image around the screen (Android)

MovingImageView Create a custom ImageView for moving image around the screen. Usage To use MovingImageView, add the module into your project and start

Albert Grobas 819 Nov 18, 2022
Flickable ImageView for Android. It's like a view of twitter's detail image.

FlickableView Flickable ImageView for Android. It's like a view of twitter's detail image. It's possible that other views animate with FlickableView.

goka 153 Nov 14, 2022
Android library written in kotlin that add a noise effect to image.

NoiseView With NoiseView you can easily add a noise effect to your image. See demo on YouTube Setup The library is pushed to jCenter() as an AAR, so y

Przemek 46 Sep 8, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022
This is a library for make auto slide image in android

Auto Image Slider Screenshot Image Slider Default Image Slider With Custom Adapter Usage Add ImageSlider to your layout

Afdhal_FA 17 Dec 1, 2022
Android Library for cropping an image at ease.

Cropper - Android Image Cropper Android Image Cropper Powerful (Zoom, Rotation, Multi-Source); Customizable (Shape, Limits, Style); Optimized (Async,

Akshat Tiwari 24 Aug 24, 2022
A library for Android provides blurred drop shadows to ImageView similar to iOS image backdrop shadows

A library for Android provides blurred drop shadows to ImageView similar to iOS image backdrop shadows.Provides fast canvas draw as no renderscript needed .The similar shadow blurred effects can also be seen in iOS Music App.

Vivek Verma 163 Dec 31, 2022
Add curve at bottom of image views and relative layouts.

Crescento Android library that adds a curve at the below of image views and relative layouts. CrescentoImageView and CrescentoContainer are the image

Shivam Satija 1.3k Nov 18, 2022
Custom ImageView to generate captcha image.

CaptchaImageView Custom ImageView to generate captcha image. Add CaptchaImageView to your layout <test.jinesh.captchaimageviewlib.CaptchaImageView

Jinesh Francis 610 Oct 18, 2022
A photoView to scale image and finish activity,高仿微信可拖拽返回PhotoView

DragPhotoView(English) 高仿微信可拖拽返回PhotoView 基于 PhotoView ##下载APK体验 特性 拖拽缩放图片,并且结束Activity 其他PhotoView所有特性如下: Out of the box zooming, using multi-touch a

androidwing 1.6k Dec 5, 2022
Custom ImageView for android with polygon shape (Android)

PolygonImageView Create a custom ImageView with polygonal forms. Usage To use PolygonImageView, add the module into your project and start to build xm

Albert Grobas 531 Dec 25, 2022
Implementation of ImageView for Android that supports zooming, by various touch gestures.

PhotoView PhotoView aims to help produce an easily usable implementation of a zooming Android ImageView. [ Dependency Add this in your root build.grad

Baseflow 18.4k Dec 30, 2022