Giter VIP home page Giter VIP logo

cropimage's Introduction

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

cropimage's People

Contributors

biokys avatar cloudbank 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  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

cropimage's Issues

Documentation

If I understand correctly, in the documentation of usage you should change the mFileTemp.getPath() to path you are getting on callback to onActivityResult.

License

Under which licence do you have put your classes (expect those from asop)?

How to draw predefined grids on the image to be cropped?

Hello!

Great library! I've had much ease in integrating and tweaking the library to my requirements. But, I have been trying to implement this in a wallpaper app, where I need multiple options for the user to set the wallpaper as, scrollable, fixed etc.

How can I draw predefined grid on the image to be cropped?
Something like this:
http://awesomescreenshot.com/0722wkzhfa

Any assistance in this regard is much appreciated!

Thanks,
Arnab

Some changes required

I need to make some changes according to my needs. I just want to have your approval on this.

Thanks!

NullPointerException on some devices

Test on SAMSUNG 2.2 and 4.1(N7100).

Because the SAMSUNG phone destroy the MainActivity and create it again when returning from the Take Picture Activity, the mImageCaptureUri is null, leads to the NullPointerException. Some phones won't destroy MainActivity when returning, so the mImageCaptureUri has its value and the program works well.

Solution:
Move the initialization of mImageCaptureUri from doTakePhotoAction() to onCreate(), and remove the milliseconde adding from the file name.

Could not import lib to eclipse

HI,
i was trying to get the lib working for my project. I tried sevarl mthods to import the lib porject or the lib into libs to buildpath etc. ma app was compiling with no errors but console says did not find class or did not find R$Layout.
The example app runs fine, compiling using eclipse with adt.
Please can you advice to get it working?
regards

Wrong image location when rotating

Starting activity, all is fine:
1
Rotating left:
2
Rotating left.. and image not in center:
3

Tested on emulator (android 2.2) and Nexus 4 (android 4.3)

Setting initial crop

Is there a way to set a crop when I call activity? for example, I save original image in order to be able to edit crop. So I save rectangle (I modified activity in order to return crop rectangle, I'll make a push request later) and I'd like to use saved rectangle to set the crop.

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap

Hi, Please help.
I am running the sample project which came with the library, I am using Samsung Galaxy S2 - Skyrocket with Android 4.1.2
So I am getting this error (Canvas: trying to use a recycled bitmap) only at the first launch and first click on "Take picture". so once I take picture then instead of start crop intent the app crashes.
this error never comes back unless I uninstall app from device and re launch it after new installation.

Following is the error I am getting:

08-22 22:59:33.075: E/AndroidRuntime(14947): FATAL EXCEPTION: Thread-47491
08-22 22:59:33.075: E/AndroidRuntime(14947): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@421fd9b0
08-22 22:59:33.075: E/AndroidRuntime(14947): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
08-22 22:59:33.075: E/AndroidRuntime(14947): at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
08-22 22:59:33.075: E/AndroidRuntime(14947): at android.graphics.Bitmap.createBitmap(Bitmap.java:604)
08-22 22:59:33.075: E/AndroidRuntime(14947): at eu.janmuller.android.simplecropimage.CropImage$1.prepareBitmap(CropImage.java:572)
08-22 22:59:33.075: E/AndroidRuntime(14947): at eu.janmuller.android.simplecropimage.CropImage$1.run(CropImage.java:578)
08-22 22:59:33.075: E/AndroidRuntime(14947): at eu.janmuller.android.simplecropimage.CropImage$6.run(CropImage.java:285)
08-22 22:59:33.075: E/AndroidRuntime(14947): at eu.janmuller.android.simplecropimage.Util$BackgroundJob.run(Util.java:175)
08-22 22:59:33.075: E/AndroidRuntime(14947): at java.lang.Thread.run(Thread.java:856)

Please help.
Thanks!

Error

Error:Failed to find: com.github.biokys:cropimage:09d567ef9d
openFile
Open in Project Structure dialog

How to resize cropping rectangle on one edge without moving the other edge?

Hi, on some of the newer Android devices, when we do crop image inside Gallery, it shows a blue border (instead of orange) and we may resize the border on say the right edge and the left edge will stay still without moving.. I think this behaviour makes more sense as it is easier to select the cropping area this way. I read the source code of this library but couldn't figure out how to modify to make it behave like I want it to... can someone better with maths help? :)

If someone know where to find the new image crop source code (with blue border) please share too.. thanks!

How to crop image without aspect ratio?

Hi,
I am using biokys lib to crop image,can someone help me how to crop image without any aspect ratio ?
when i set the aspect ratio to 0 in
intent.putExtra(CropImage.ASPECT_X, 0);
intent.putExtra(CropImage.ASPECT_Y, 0);
ans start the crop activity,in the crop screen when i change the rectangle line to new place the opposite side line is increasing proportionally.I dont want this effect.

Getting a banded low quality image.

I'm trying to crop camera, but the result is that mi cropped image is being banded and with a low quality.

¿Is this the normal behavior or I'm doing something wrong?

Downloadable jar

Hi,

Can you provide a downloadable jar file? Compiling the source code as an imported module won't work.

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

Trying to recycle Bitmap

Hi i am getting strange exception when i take picture from camera and try to crop it.
Here is my log cat.

I am facing this issue on Galaxy Grand with os 4.2.2

11-25 17:44:28.909: E/AndroidRuntime(30645): FATAL EXCEPTION: Thread-6510
11-25 17:44:28.909: E/AndroidRuntime(30645): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@42765a00
11-25 17:44:28.909: E/AndroidRuntime(30645): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
11-25 17:44:28.909: E/AndroidRuntime(30645): at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
11-25 17:44:28.909: E/AndroidRuntime(30645): at android.graphics.Bitmap.createBitmap(Bitmap.java:646)
11-25 17:44:28.909: E/AndroidRuntime(30645): at eu.janmuller.android.simplecropimage.CropImage$1.prepareBitmap(CropImage.java:558)
11-25 17:44:28.909: E/AndroidRuntime(30645): at eu.janmuller.android.simplecropimage.CropImage$1.run(CropImage.java:564)
11-25 17:44:28.909: E/AndroidRuntime(30645): at eu.janmuller.android.simplecropimage.CropImage$6.run(CropImage.java:271)
11-25 17:44:28.909: E/AndroidRuntime(30645): at eu.janmuller.android.simplecropimage.Util$BackgroundJob.run(Util.java:175)
11-25 17:44:28.909: E/AndroidRuntime(30645): at java.lang.Thread.run(Thread.java:856)

Not working on some devices.

I have samsung galaxy Grand and i am not able to run on this device it just gets close without any error. do not redirecting to crop section after selecting image.

NullPointerException

06-20 18:12:20.450: E/AndroidRuntime(8667): Caused by: java.lang.NullPointerException
06-20 18:12:20.450: E/AndroidRuntime(8667): at eu.janmuller.android.simplecropimage.CropImage.onCreate(CropImage.java:98)
06-20 18:12:20.450: E/AndroidRuntime(8667): at android.app.Activity.performCreate(Activity.java:5206)
06-20 18:12:20.450: E/AndroidRuntime(8667): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-20 18:12:20.450: E/AndroidRuntime(8667): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-20 18:12:20.450: E/AndroidRuntime(8667): ... 11 more

Hi i am getting nullpointer exception in your library class at

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
Please help me with this!...

When i used your project as libarary it was giving me error that fail to deliver result. stating activity is not declared in manifest. then i copied your package to my project that error went way .. but now getting nullpointer exception.

Portrait Image rotated on crop view

When I take a picture in portrait mode, the crop view automatically rotates it by 90 degrees. Does not seem to happen in landscape. Is there a way to prevent this?

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?

Support for disabling resizing option

I am using this library in a situation where I don't want to allow user to change the size of the cropper rectangle. I have made some changes in the library to add this support, but I don't know the process of submitting my changes. Can any one guide?

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.

java.lang.IllegalArgumentException: View not attached to window manager

Hi,
I receive this crash from crittercism. The only information that I have is that the activity eu.janmuller.android.simplecropimage.CropImage was open when the crash happens. It has occur only one time, any ideas?

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:672)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:368)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:160)
at android.app.Dialog.dismissDialog(Dialog.java:319)
at android.app.Dialog$1.run(Dialog.java:119)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)

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?

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.