Giter Club home page Giter Club logo

croperino's Introduction

Croperino

A simple image cropping tool for your android applications (v2.0.0)

Android Arsenal

Supported SDK and Gradle Version:

  • Minimum SDK Version 24
  • Gradle 8.4

Features:

  • Camera and/or gallery calls.
  • Face recognition
  • Cropping of Image based on Scale (Aspect Ratio)
  • Customizing button and background
  • Performance and compression improvements
  • Removed permission support (still has issues and different per Device OS)
  • Chooser capability is no longer recommended

Getting Started

Make sure to have Android Studio

Gradle

In your root build.gradle, add at the end of the repositories:

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

If you are using newer Android Studio Project structure that is using build.gradle.kts, you can instead declare inside your settings.gradle.kts:

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
      google()
      mavenCentral()
      maven (url = "https://jitpack.io")
    }
}

Add the dependency

implementation 'com.github.mikekpl:croperino:2.0.0'

Usage

Permissions

IMPORTANT!! Please manage permissions accordingly (the library's permission management is bugged at the moment)

  • Camera permission is still being checked, but it would be better if you're able to handle permission prompts
  • Gallery access should have read and write access as well as ACTION_PICK capability

Sample Usage

Initialization:

CroperinoConfig("IMG_" + System.currentTimeMillis() + ".jpg", "/MikeLau/Pictures", "/sdcard/MikeLau/Pictures")
CroperinoFileUtil.setupDirectory(this)

Make sure corresponding permissions are already granted prior to calling these functions:

// Prepare Camera - Make sure Camera permission is already allowed otherwise it won't work
Croperino.prepareCamera(this)

// Prepare Gallery - Make sure Read / Write / Manage External Storage is already allowed otherwise it won't work
Croperino.prepareGallery(this)

onActivityResult

  • Aspect Ratio X = 1 / Y = 1 will produce fixed square view
  • Aspect Ratio X = 0 / Y = 0 will produce customizable square view width or height can be customized
  • Color and Background Color should be XML format e.g. R.color.gray, place 0 if no change is meant to colors
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case CroperinoConfig.REQUEST_TAKE_PHOTO:
            if (resultCode == Activity.RESULT_OK) {
                /* Parameters of runCropImage = File, Activity Context, Image is Scalable or Not, Aspect Ratio X, Aspect Ratio Y, Button Bar Color, Background Color */
                Croperino.runCropImage(CroperinoFileUtil.getTempFile(), MainActivity.this, true, 1, 1, R.color.gray, R.color.gray_variant);
            }
            break;
        case CroperinoConfig.REQUEST_PICK_FILE:
            if (resultCode == Activity.RESULT_OK) {
                CroperinoFileUtil.newGalleryFile(data, MainActivity.this);
                Croperino.runCropImage(CroperinoFileUtil.getTempFile(), MainActivity.this, true, 0, 0, R.color.gray, R.color.gray_variant);
            }
            break;
        case CroperinoConfig.REQUEST_CROP_PHOTO:
            if (resultCode == Activity.RESULT_OK) {
                Uri i = Uri.fromFile(CroperinoFileUtil.getTempFile());
                ivMain.setImageURI(i);
                //Do saving / uploading of photo method here.
                //The image file can always be retrieved via CroperinoFileUtil.getTempFile()
            }
            break;
        default:
            break;
    }
}

Proguard

-dontwarn com.mikelau.croperino.**
-keep class com.mikelau.croperino.** { *; }
-keep interface com.mikelau.croperino.** { *; }

Contributing

  1. Fork it (https://github.com/mikekpl/croperino/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

License

The MIT License (MIT)

Copyright (c) 2013 Mike Lau

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.

croperino's People

Contributors

mikekpl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

croperino's Issues

Lopping issue in crop

Lopping happens in crop section after capturing photo.
Croperino.prepareCamera(HomeScreen.this);
case CroperinoConfig.REQUEST_TAKE_PHOTO:
if (resultCode == Activity.RESULT_OK) {
Croperino.runCropImage(CroperinoFileUtil.getmFileTemp(), HomeScreen.this, true, 1, 1, 0, 0);
}
break;
case CroperinoConfig.REQUEST_PICK_FILE:
if (resultCode == Activity.RESULT_OK) {
CroperinoFileUtil.newGalleryFile(data, HomeScreen.this);
Croperino.runCropImage(CroperinoFileUtil.getmFileTemp(), HomeScreen.this, true, 1, 1, 0, 0);
}
break;
case CroperinoConfig.REQUEST_CROP_PHOTO:
if (resultCode == Activity.RESULT_OK) {

//manage photo
}
Device Htc M8
Version 5.0.1

Make cropping arrow visible always

Hey, First thankyou for the great library. I need to make arrow always visible as soon ImageView appears. Can you please tell me what changes to make to get desired result

Image file captured not found

When I give permissions to gallery and camera everything is OK. But after that when I turn off permission for gallery in app settings, camera also doesnt work and error message "Image file captured not found" is appeared.

Use content:// Uri for a file instead of a file:/// Uri

"Passing file:// URIs outside the package domain may leave the receiver with an unaccessible path. Therefore, attempts to pass a file:// URI trigger a FileUriExposedException (Android N). The recommended way to share the content of a private file is using the FileProvider."

Unable to get provider android.support.v4.content.FileProvider

While trying to integrate cropino I'm getting following error.

java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.gusto.kvartha-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gusto.kvartha-1, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5144)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4721)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4661)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5372)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:970)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.gusto.kvartha-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gusto.kvartha-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:5129)

New logo

Hi, @ekimual I am a graphic designer, I want to help others in graphic design.

After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

Original image affected!!

original image being cropped upon using this library. Cannot find any solution for this! Help @ekimual
I want to get the image from gallery/camera, crop the image, store in another directory (without cropping the original image), and then use the new cropped image!

Saving to another file

Great plugin my friend !!

Hello i want to save to another file and no overwrite the original file, this is possible ??

Rename `getmFileTemp`

That function name has been generated but not tweaked. I suggest maybe getTempFile instead.

Crop Window size

How can we change crop window size according to mobile capture image size? What kind of changes needed in ratio?

Camera error

Can not require Camera permission automatically. When I choose Camera it show noti "Storage Full".
I set the permission manually then it can open the camera, but can not get image from camera after taken.

Is it safe to remove <uses-feature android:name="android.hardware.camera.autofocus" />?

Hello, I've been using Croperino for my app.
it's been the best and fits my requirement the most for choosing pictures and crop them.

But since i use this feature line in manifest, some of my users with low end devices which have no autofocus feature, cannot download this app. playstore said the device is incompatible.
<uses-feature android:name="android.hardware.camera.autofocus" />

I've tested removing this line in manifest, the app runs well and can use the camera nicely,
but is it really safe to remove this feature and keep using this library?

Replace Crouton for Snackbar

The Crouton library is not in development anymore and Android has introduce the Snackbar (also for old versions through the support design library).

I think that replace the crouton dependency for a native solution as Snackbar is more than appropriated.

updating original image

it's a nice plugin for cropping but I don't want to store image and also don't want to update original one, just want to store the image in temp file so it cannot be affected to original image. @ekimual

Failed to prepare camera

I get this error in Samsung s7(6.0, 7.0) and HTC m7(5.0)
but works in SONY m4(5.0), Nexus 6(6.0)

E/Croperino: Failed to prepare camera: java.io.IOException: No such file or directory at java.io.UnixFileSystem.createFileExclusively0(Native Method) at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:280) at java.io.File.createNewFile(File.java:948) at java.io.File.createTempFile(File.java:1862) at com.mikelau.croperino.CroperinoFileUtil.newCameraFile(CroperinoFileUtil.java:60) at com.mikelau.croperino.Croperino.prepareCamera(Croperino.java:72) at com.demo.sercomm.mwc2017.MainActivity$3.onClick(MainActivity.java:256) at android.view.View.performClick(View.java:6207) at android.view.View$PerformClick.run(View.java:23639) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

Image is not saved.

I have used the code as you say but it is not saving cropped images in any directory either in my custom folder or DCIM (inbuilt). help! @ekimual

dont start CropImage activity when use this library within fragment

in fragment onCreateView add this code:
new CroperinoConfig("IMG_" + System.currentTimeMillis() + ".jpg", "/MikeLau/Pictures", "/sdcard/MikeLau/Pictures"); CroperinoFileUtil.verifyStoragePermissions(getActivity()); CroperinoFileUtil.setupDirectory(getContext());
and add this code in fragment class:

`private void openImagePickerIntent() {
if (CroperinoFileUtil.verifyStoragePermissions(getActivity())) {
prepareChooser();
}else{

    }
}
private void prepareChooser() {
    Croperino.prepareChooser(getActivity(), "انتخاب تصویر از ...", ContextCompat.getColor(getContext(), android.R.color.background_dark));
}
private void prepareCamera() {
    Croperino.prepareCamera(getActivity());
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);


    Log.d(CONST.APP_LOG,"onActit result");
    switch (requestCode) {
        case CroperinoConfig.REQUEST_TAKE_PHOTO:
            if (resultCode == Activity.RESULT_OK) {
                Croperino.runCropImage(CroperinoFileUtil.getmFileTemp(), getActivity(), true, 16, 9, 0, 0);
            }
            break;
        case CroperinoConfig.REQUEST_PICK_FILE:
            if (resultCode == Activity.RESULT_OK) {
                CroperinoFileUtil.newGalleryFile(data, getActivity());
                Croperino.runCropImage(CroperinoFileUtil.getmFileTemp(), getActivity(), true, 16, 9, 0, 0);
            }
            break;
        case CroperinoConfig.REQUEST_CROP_PHOTO:
            if (resultCode == Activity.RESULT_OK) {
                Uri i = Uri.fromFile(CroperinoFileUtil.getmFileTemp());
                //ivMain.setImageURI(i);
                Log.d(CONST.APP_LOG,"url: " + i.getPath());
            }
            break;
        default:
            break;
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode == CroperinoFileUtil.REQUEST_CAMERA) {
        for (int i = 0; i < permissions.length; i++) {
            String permission = permissions[i];
            int grantResult = grantResults[i];

            if (permission.equals(Manifest.permission.CAMERA)) {
                if (grantResult == PackageManager.PERMISSION_GRANTED) {
                    prepareCamera();
                }
            }
        }
    } else if (requestCode == CroperinoFileUtil.REQUEST_EXTERNAL_STORAGE) {
        boolean wasReadGranted = false;
        boolean wasWriteGranted = false;

        for (int i = 0; i < permissions.length; i++) {
            String permission = permissions[i];
            int grantResult = grantResults[i];

            if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
                if (grantResult == PackageManager.PERMISSION_GRANTED) {
                    wasReadGranted = true;
                }
            }
            if (permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                if (grantResult == PackageManager.PERMISSION_GRANTED) {
                    wasWriteGranted = true;
                }
            }
        }

        if (wasReadGranted && wasWriteGranted) {
            prepareChooser();
        }
    }
}`

when start activity and select file from gallery or camera "CropImage " activity don't open and nothing happend
how to solve this problem ?

New Icon

Hi, @ekimual I am a graphic designer, I want to help others in graphic design.
sorry for the closed issues. I accidentally clicked on it.
After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new icon / logo. what do you think? you want it?

How to use this library in a fragment

I downloaded this library and I added to the project
Inside the activity it works correctly but
Do not work inside the fragment and the onCreateView
What is the solution?

Camera access failed

each time I try to select the camera option I just get a "camera access failed" drop-down message

Error - Permission Denied

I can't get file from external memory (sd card). when i get file from it and click crop the app force close.
Please fix this bug. thanks

How to change the aspect ratio ?

@ekimual
The image derived from the camera, goes to the crop screen.
but the aspect ratio of the cropper is always square, how do i keep it free size ?

original image being cropped

As told in the sample, we have changed just directory name and directory also created but the image still cropped and save to original one.please help. @ekimual

How to set cropview to be fix as square, it should not be zoom in or zoom out rather it should be fixed size.

I have implemented your Project in that CropImageView I have comment out ZoomIn and ZoomOut method but nothing has changed .

  @Override
    protected void zoomIn() {

        super.zoomIn();
        for (HighlightView hv : mHighlightViews) {
            hv.mMatrix.set(getImageMatrix());
            hv.invalidate();
        }
    }

    @Override
    protected void zoomOut() {

        super.zoomOut();
        for (HighlightView hv : mHighlightViews) {
            hv.mMatrix.set(getImageMatrix());
            hv.invalidate();
        }
    }

hope you suggest me way to find my solution.

Original image changed when cropping

When I choose to crop an image from gallery, it changes the original image. I know this has been confirmed as fixed from v1.1.2 however it is still happening for me. I have used the same code given in your example usage which seems to create a temporary file for the cropped, image but it still changes the original. Is there anything I'm missing?
Thanks

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.