Giter VIP home page Giter VIP logo

simplecropview's Introduction

SimpleCropView

build status Android Arsenal Android Gems

The SimpleCropView is an image cropping library for Android.
It simplifies your code for cropping image and provides an easily customizable UI.

Supported on API Level 14 and above.

demo

Table of Contents

Download

Include the following dependency in your build.gradle file. Please use the latest version available.

repositories {
    jcenter()
}
dependencies {
    compile 'com.isseiaoki:simplecropview:1.1.8'
}

Example

Image Cropping

Add permission in AndroidManifest.xml file.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Add the com.isseiaoki.simplecropview.CropImageView to your layout XML file.

NOTE: The image is scaled to fit the size of the view by maintaining the aspect ratio. WRAP_CONTENT will be ignored.

<com.isseiaoki.simplecropview.CropImageView
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cropImageView"
    android:layout_weight="1"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:scv_crop_mode="fit_image"
    custom:scv_background_color="@color/windowBackground"
    custom:scv_handle_color="@color/colorAccent"
    custom:scv_guide_color="@color/colorAccent"
    custom:scv_overlay_color="@color/overlay"
    custom:scv_frame_color="@color/colorAccent"
    custom:scv_handle_size="14dp"
    custom:scv_touch_padding="8dp"
    custom:scv_handle_show_mode="show_always"
    custom:scv_guide_show_mode="show_always"
    custom:scv_min_frame_size="50dp"
    custom:scv_frame_stroke_weight="1dp"
    custom:scv_guide_stroke_weight="1dp"/>

Load image from sourceUri.

mCropView = (CropImageView) findViewById(R.id.cropImageView);

mCropView.load(sourceUri).execute(mLoadCallback);

with RxJava,

mCropView.load(sourceUri).executeAsCompletable();

Crop image and save cropped bitmap in saveUri.

mCropView.crop(sourceUri)
    .execute(new CropCallback() {
  @Override public void onSuccess(Bitmap cropped) {
    mCropView.save(cropped)
        .execute(saveUri, mSaveCallback);
  }

  @Override public void onError(Throwable e) {
  }
});

with RxJava,

mCropView.crop(sourceUri)
    .executeAsSingle()
    .flatMap(new Function<Bitmap, SingleSource<Uri>>() {
      @Override public SingleSource<Uri> apply(@io.reactivex.annotations.NonNull Bitmap bitmap)
              throws Exception {
        return mCropView.save(bitmap)
            .executeAsSingle(saveUri);
      }
    })
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Consumer<Uri>() {
      @Override public void accept(@io.reactivex.annotations.NonNull Uri uri) throws Exception {
        // on success
      }
    }, new Consumer<Throwable>() {
      @Override public void accept(@io.reactivex.annotations.NonNull Throwable throwable)
              throws Exception {
        // on error
      }
    });

Image Rotation

SimpleCropView supports rotation by 90 degrees.

cropImageView.rotateImage(CropImageView.RotateDegrees.ROTATE_90D); // rotate clockwise by 90 degrees
cropImageView.rotateImage(CropImageView.RotateDegrees.ROTATE_M90D); // rotate counter-clockwise by 90 degrees

For a working implementation of this project, see sample project.

Load Image

  • load(sourceUri).execute(mLoadCallback);

with RxJava,

  • load(sourceUri).executeAsCompletable();

These method load Bitmap in efficient size from sourceUri. You don't have to care for filePath and image size. You can also use Picasso or Glide.

Apply Thumbnail

You can use blurred image for placeholder.

mCropView.load(result.getData())
         .useThumbnail(true)
         .execute(mLoadCallback);

Crop and Save Image

mCropView.crop(sourceUri)
    .execute(new CropCallback() {
  @Override public void onSuccess(Bitmap cropped) {
    mCropView.save(cropped)
        .execute(saveUri, mSaveCallback);
  }

  @Override public void onError(Throwable e) {
  }
});

with RxJava,

mCropView.crop(sourceUri)
    .executeAsSingle()
    .flatMap(new Function<Bitmap, SingleSource<Uri>>() {
      @Override public SingleSource<Uri> apply(@io.reactivex.annotations.NonNull Bitmap bitmap)
              throws Exception {
        return mCropView.save(bitmap)
                .executeAsSingle(saveUri);
      }
    })
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Consumer<Uri>() {
      @Override public void accept(@io.reactivex.annotations.NonNull Uri uri) throws Exception {
        // on success
      }
    }, new Consumer<Throwable>() {
      @Override public void accept(@io.reactivex.annotations.NonNull Throwable throwable)
              throws Exception {
        // on error
      }
    });

These cropping method use full size bitmap taken from sourceUri for cropping. If sourceUri is null, the Uri set in load(Uri) is used. After cropping, it saves cropped image in saveUri.

Compress Format

You can use 3 compress format, PNG(default),JPEG, and WEBP.

setCompressFormat(Bitmap.CompressFormat.JPEG);

Compress Quality

You can also set compress quality. 0~100(default)

setCompressQuality(90);

Customization

Maximum Output Size

You can set max size for output image. The output image will be scaled within given rect.

setOutputMaxSize(300, 300);

Fixed Output Size

You can also set fixed output width/height.

setOutputWidth(100); // If cropped image size is 400x200, output size is 100x50
setOutputHeight(100); // If cropped image size is 400x200, output size is 200x100

CropMode

The option for the aspect ratio of the image cropping frame.

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setCropMode(CropImageView.CropMode.RATIO_16_9);

Values

FIT_IMAGE, RATIO_4_3, RATIO_3_4, SQUARE(default), RATIO_16_9, RATIO_9_16, FREE, CUSTOM, CIRCLE, CIRCLE_SQUARE

Rect Crop

FREE: Non-Fixed aspect ratio mode RATIO_X_Y, SQUARE: Fixed aspect ratio mode FIT_IMAGE: Fixed aspect ratio mode. The same aspect ratio as the original photo.

If you need other aspect ratio, use setCustomRatio(int ratioX, int ratioY);

demo

Circle Crop

CIRCLE: Fixed aspect ratio mode. Crop image as circle. CIRCLE_SQUARE: Fixed aspect ratio mode. Show guide circle, but save as square.(getRectBitmap() is removed.)

MinimumFrameSize

The minimum size of the image cropping frame in dp.(default:50)

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setMinFrameSizeInDp(100);

demo

InitialFrameScale

The initial frame size of the image cropping frame. 0.01~1.0(default)

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setInitialFrameScale(1.0f);
scale Appearance
0.5
0.75
1.0 (default)

Save and Restore FrameRect

You can save and restore frame rect as follows. See sample project for more details.

  • Save FrameRect
mCropView.getActualCropRect()
  • Restore FrameRect
mCropView.load(result.getData())
         .initialFrameRect(mFrameRect)
         .execute(mLoadCallback);

Color

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setBackgroundColor(0xFFFFFFFB);
cropImageView.setOverlayColor(0xAA1C1C1C);
cropImageView.setFrameColor(getResources().getColor(R.color.frame));
cropImageView.setHandleColor(getResources().getColor(R.color.handle));
cropImageView.setGuideColor(getResources().getColor(R.color.guide));

Stroke Weight and Handle Size

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setFrameStrokeWeightInDp(1);
cropImageView.setGuideStrokeWeightInDp(1);
cropImageView.setHandleSizeInDp(getResources().getDimension(R.dimen.handle_size));

Handle Touch Padding

Additional touch area for the image cropping frame handle.

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setTouchPadding(16);

Handle and Guide ShowMode

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
cropImageView.setHandleShowMode(CropImageView.ShowMode.SHOW_ALWAYS);
cropImageView.setGuideShowMode(CropImageView.ShowMode.SHOW_ON_TOUCH);

Values

SHOW_ALWAYS(default), NOT_SHOW, SHOW_ON_TOUCH
Handle ShowMode Guide ShowMode Appearance
SHOW_ALWAYS SHOW_ALWAYS
NOT_SHOW NOT_SHOW
SHOW_ALWAYS NOT_SHOW
SHOW_ALWAYS SHOW_ON_TOUCH
SHOW_ON_TOUCH NOT_SHOW

Animation

SimpleCropView supports rotate animation and frame change animation.

Enabled

Toggle whether to animate. true is default.

setAnimationEnabled(true);

Duration

Set animation duration in milliseconds. 100 is default.

setAnimationDuration(200);

Interpolator

Set interpolator of animation. DecelerateInterpolator is default. You can also use your custom interpolator.

setInterpolator(new AccelerateDecelerateInterpolator());

Picasso and Glide Compatibility

com.isseiaoki.simplecropview.CropImageView is a kind of ImageView. You can use it with Picasso or Glide as follows:

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
Picasso.with(context).load(imageUrl).into(cropImageView);

or

CropImageView cropImageView = (CropImageView)findViewById(R.id.cropImageView);
Glide.with(context).load(imageUrl).into(cropImageView);

Some option does not work correctly because CropImageView does not support ImageView.ScaleType.

Debug

You can use debug display.

setDebug(true);

XML Attributes

XML sample here.

<com.isseiaoki.simplecropview.CropImageView
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cropImageView"
    android:layout_weight="1"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:scv_img_src="@drawable/sample5"
    custom:scv_crop_mode="fit_image"
    custom:scv_background_color="@color/windowBackground"
    custom:scv_overlay_color="@color/overlay"
    custom:scv_frame_color="@color/colorAccent"
    custom:scv_handle_color="@color/colorAccent"
    custom:scv_guide_color="@color/colorAccent"
    custom:scv_guide_show_mode="show_always"
    custom:scv_handle_show_mode="show_always"
    custom:scv_handle_size="14dp"
    custom:scv_touch_padding="8dp"
    custom:scv_min_frame_size="50dp"
    custom:scv_frame_stroke_weight="1dp"
    custom:scv_guide_stroke_weight="1dp"
    custom:scv_crop_enabled="true"
    custom:scv_initial_frame_scale="1.0"
    custom:scv_animation_enabled="true"
    custom:scv_animation_duration="200"
    custom:scv_handle_shadow_enabled="true"/>
XML Attribute
(custom:)
Related Method Description
scv_img_src setImageResource(int resId) Set source image.
scv_crop_mode setCropMode(CropImageView.CropMode mode) Set crop mode.
scv_background_color setBackgroundColor(int bgColor) Set view background color.
scv_overlay_color setOverlayColor(int overlayColor) Set image overlay color.
scv_frame_color setFrameColor(int frameColor) Set the image cropping frame color.
scv_handle_color setHandleColor(int frameColor) Set the handle color.
scv_guide_color setGuideColor(int frameColor) Set the guide color.
scv_guide_show_mode setGuideShowMode(CropImageView.ShowMode mode) Set guideline show mode.
scv_handle_show_mode setHandleShowMode(CropImageView.ShowMode mode) Set handle show mode.
scv_handle_size setHandleSizeInDp(int handleDp) Set handle radius in density-independent pixels.
scv_touch_padding setTouchPaddingInDp(int paddingDp) Set the image cropping frame handle touch padding(touch area) in density-independent pixels.
scv_min_frame_size setMinFrameSizeInDp(int minDp) Set the image cropping frame minimum size in density-independent pixels.
scv_frame_stroke_weight setFrameStrokeWeightInDp(int weightDp) Set frame stroke weight in density-independent pixels.
scv_guide_stroke_weight setGuideStrokeWeightInDp(int weightDp) Set guideline stroke weight in density-independent pixels.
scv_crop_enabled setCropEnabled(boolean enabled) Set whether to show the image cropping frame.
scv_initial_frame_scale setInitialFrameScale(float initialScale) Set Set initial scale of the frame.(0.01 ~ 1.0)
scv_animation_enabled setAnimationEnabled(boolean enabled) Set whether to animate.
scv_animation_duration setAnimationDuration(int durationMillis) Set animation duration.
scv_handle_shadow_enabled setHandleShadowEnabled(boolean handleShadowEnabled) Set whether to show handle shadows.

Developed By

Issei Aoki - [email protected]

Users

If you are using my library, please let me know your app name : )

For Xamarin

https://bitbucket.org/markjackmilian/xam.droid.simplecropview

Thanks a million to Marco!!!

License

The MIT License (MIT)

Copyright (c) 2015 Issei Aoki

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.

simplecropview's People

Contributors

bryant1410 avatar igreenwood avatar liaohuqiu avatar mapyo avatar mlnkrish avatar mronyszko avatar rainer-lang avatar sumimakito avatar tinsuke 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  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

simplecropview's Issues

IllegalArgumentException when cropping certain size image

Hi,

I got this error message whenever I'm trying to crop 1200 x 1200px (or its multiply 2400 x 2400 etc) image.
java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
at android.graphics.Bitmap.createBitmap(Bitmap.java:669)
at com.isseiaoki.simplecropview.CropImageView.getCroppedBitmap(CropImageView.java:1012)

I called getCroppedBitmap() without resize the image (moving the handle)

I'm using:
cropMode="ratio_1_1"
handleSize="12dp"
minFrameSize="200dp"
initialFrameScale="1.0"

Can you help me? Thank you

Option to keep Exif data

Currently when you crop a photo all the exif data from the original photo gets nuked. There should be a way to keep the exif data from the original photo so the gps data and time stamp dont get deleted

Jar version

is there any jar version for this library? because of some limitation I unable to use gradle in my projects, thanks

please remove "<application android:label="@string/app_name">"

Error:Execution failed for task ':app:processDevDebugManifest'.

Manifest merger failed : Attribute application@label value=(@string/XYZ) from AndroidManifest.xml:74:9-40
is also present at [com.isseiaoki:simplecropview:1.0.13] AndroidManifest.xml:11:18-50 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to element at AndroidManifest.xml:71:5-374:19 to override.

Critical issue

Hi guys. You are made awesome widget. But it has one critical bug. When set widget's width or height to match_parent it became laggy. Looks like something going wrong on measure or on layout stage or something else running into the loop.
GPU monitor http://screencloud.net/v/xc3i
Memory monitor http://screencloud.net/v/1Y8k (leaking memory)
I have only one activity with SimpleCropView width and height are match_parent.

Sorry, my mistake. I loaded 8 megapixels bitmap into view directly.

Overlay drawing is lacking when selecting certain photos

When I select certain photos overlay drawing is lacking a line in top and/or bottom. Here's a screenshot of what is happening:

_20160426_155608

As you can see in the screenshot above, the top line of overlay is not getting drawn.
Here is how I am using CropImageView

<com.isseiaoki.simplecropview.CropImageView
        android:id="@+id/cropImageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp"
        custom:scv_crop_mode="free"
        custom:scv_guide_color="@color/accentColor"
        custom:scv_handle_color="@color/accentColor"
        custom:scv_frame_color="@color/accentColor"
        custom:scv_background_color="@color/solidBlack"
        custom:scv_handle_size="8dp"
        custom:scv_touch_padding="10dp" />

Let me know if you need more info.
I can also email you the original photo which caused this.

java.lang.IllegalArgumentException: x + width must be <= bitmap.width()

Hello,

I am getting this exception:

java.lang.IllegalArgumentException: x + width must be <= bitmap.width()
 at android.graphics.Bitmap.createBitmap(Bitmap.java:698)
 at com.isseiaoki.simplecropview.CropImageView.getCroppedBitmap(SourceFile:1012)
 at bci.onClick(SourceFile:1064)
 at android.view.View.performClick(View.java:4463)
 at android.view.View$PerformClick.run(View.java:18801)
 at android.os.Handler.handleCallback(Handler.java:808)
 at android.os.Handler.dispatchMessage(Handler.java:103)
 at android.os.Looper.loop(Looper.java:193)
 at android.app.ActivityThread.main(ActivityThread.java:5299)
 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:829)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
 at dalvik.system.NativeStart.main(Native Method)

every once in a while. Any idea on what's happening there?

Cheers,
Sakis

Disable cropping resize

I just want to fit the image cropping frame to fit the device width or Image width and height accordingly to maintain aspect ratio. I want to make it fix so that use can not resize it just can drag it to select desire portion of the image.

If I use setEnabled(false); then it also stops dragging feature. I want to provide the user to select the portion of the image to crop but don't want to resize the cropping area (disable resize using 4 dots at the corner of grid)

So how can I achieve this? Can you please provide this feature also. Also the modes like fit to width (height should be as it is to maintain aspect ration) same way fit to height and so on....

Unmarshalling unknown type code 51 at offset 400

Hi,

We are getting an error like :

java.lang.RuntimeException: Unable to start activity ComponentInfo{....CropImageActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@41b317a0: Unmarshalling unknown type code 51 at offset 400
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2279)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2329)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5214)
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:814)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:630)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@41b317a0: Unmarshalling unknown type code 51 at offset 400
at android.os.Parcel.readValue(Parcel.java:2092)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2396)
at android.os.Parcel.readSparseArray(Parcel.java:1747)
at android.os.Parcel.readValue(Parcel.java:2082)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2329)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1273)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1745)
at android.app.Activity.onRestoreInstanceState(Activity.java:944)
at android.app.Activity.performRestoreInstanceState(Activity.java:916)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2329)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5214)
            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:814)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:630)
            at dalvik.system.NativeStart.main(Native Method)

Can you help me?

Thanks

Inconsistency when changing mIsCropEnabled value

Consider this case. I enable crop using setCropEnabled(true) and adjust crop frame. Then I disable crop using setCropEnabled(false). Now if I call startCrop() I suppose it should ignore the previously set crop frame, but it will crop according to the frame which was set when crop was enabled.

I think calcCropRect() should take the value of mIsCropEnabled into account. Or at least there should be a public method to reset crop frame.

Sorry if I am buzzing you with a lot of issues. Thank you for taking the time to check these out.

NullPointException in Utils.getExifOrientation()

public static int getExifOrientation(Context context, Uri uri) {
        String authority = uri.getAuthority().toLowerCase();
        int orientation;
        if (authority.endsWith("media")) {
            orientation = getExifRotation(context, uri);
        } else {
            orientation = getExifRotation(getFileFromUri(context, uri));
        }
        return orientation;
    }

uri.getAuthority() == null will cause NullPointException. For example: Uri "/storage/emulated/0/homerun/homerun-Pictures/IMG_20160615_075035.jpg"

Cannot view the crop editor activity in phone(api 19) but able to view it in emulator nexus4 api22?

I can able to crop image in emulator but can not do it in real device of api 19 . can anyone please help me with this issue?
` if (requestCode == REQUEST_CHOOSE_FILE) {
Uri imageUri = data.getData();
// filename= data.getData().getLastPathSegment();
filename= data.getData().getPath();

            try {

                Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
                Intent i=new Intent(MyProfileActivity.this,SetImage.class);
                i.putExtra("Bitmap",bitmap);
                startActivity(i);

             profilePic.setImageBitmap(bitmap);
             save.setVisibility(View.VISIBLE);
            } catch (IOException e) {
                e.printStackTrace();
            }
}`

This is my code and I can not go to setImage activity which has code for cropping the image in phone.
Code of setImage activity is here:

` @OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_image);

    cancelbutton = (Button) findViewById(R.id.btnCancel);
    ok = (Button) findViewById(R.id.btnOk);
    crop=(Button)findViewById(R.id.btnCrop);
    croppedImageView = (ImageView) findViewById(R.id.croppedimageView);
    image = (CropImageView) findViewById(R.id.imageView);
    image.setCropMode(CropImageView.CropMode.RATIO_1_1);
    image.setMinFrameSizeInDp(100);
    image.setBackgroundColor(0xFFFFFFFB);
    image.setOverlayColor(0xAA1C1C1C);
    image.setFrameColor(getResources().getColor(R.color.primary));
    image.setHandleColor(getResources().getColor(R.color.white));
    image.setGuideColor(getResources().getColor(R.color.white));
    cancelbutton.setOnClickListener(this);
    ok.setOnClickListener(this);
    crop.setOnClickListener(this);

    String imagePath = getIntent().getStringExtra("imagePath");

    Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("Bitmap");
    image.setImageBitmap(bitmap);

}`

setImageUrl

there is something wrong with setImageUrl.

Performance issues on portrait images

Firstly, fantastic library, I like the way it looks, how easy is to implement and use it.

I only have one issue and I don't know to what it is related: when I am working with a portrait image, there are performance issues with dragging the rectangle or resizing it. This does not happen when using a landscape picture, even if the landscape picture's size is bigger.

ClassCastException ColorDrawable cannot be cast to BitmapDrawable

java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
                                                                           at com.isseiaoki.simplecropview.CropImageView.getBitmap(CropImageView.java:924)
                                                                           at com.isseiaoki.simplecropview.CropImageView.setImageResource(CropImageView.java:964)

Maintain aspect ratio when modifying output dimensions

Hey,

I ran into an issue when setting output sizes. The resizing seems to derive an aspect ratio from getRatioX() and getRatioY(), which, in the typical use case, results in an image of size 1:1. What would be much more expected would be to resize the cropped selection and maintain that aspect ratio rather than overwrite/ignore it.

This change would be very simple. You would just need to change some code in CropImageView.java in the method scaleBitmapIfNeeded(Bitmap). The only line that needs changing would be this:

float imageRatio = getRatioX() / getRatioY();

to

float imageRatio = (float) width / (float) height;

(Maybe change the var name to croppedRatio?)

I've currently copied the class locally and replaced this line and have it functioning correctly. However, I would love to get this in the library. I don't mind making a PR. Let me know ^_^

Russell

Very Slow on Android 5.1.1

The SimpleCropView is very slow on Android 5.1.1.
I tested it on others and it looks great, but in Android 5.1.1 is too slow

Message: skip frames, much work on main thread

Response: The image was too big.

Smasung Note 3 Crop Screen

After approving the taken image we get teh crop screen. But, the image view does not contain an image and the crop region is near pure white, I've attached a screenshot as a reference. It is worthy to note that this does not happen on any other device we have tested on thus far.

Image of Bug

Setting Drawable to SimpleCropView causes undefined behavior

Very nice and clean library!

I was trying to use it with Picasso. Images load just fine, they show up, but without cropping frame. Also, trying to rotate CropView with the new rotation method causes crash:

Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at com.isseiaoki.simplecropview.CropImageView.rotateImage(CropImageView.java:972)

The actual reason is that Picasso uses PicassoDrawable internally to load images into ImageViews. And SimpleCropView doesn't have corresponding method overloaded. As a workaround, I use callback to get bitmap and set it directly to CropView. But it would be nice if it worked out of box.

Just crop the Image displayed in the ImageView?

Sometimes, You want to crop an large picture, it may be 8000x6000, And then, App use a Loader such as picasso to display a thumbnail image to the ImageView to prevent OutOfMemory crash. Maybe, a 400x300 picture to displayed in the ImageView. Then cropping of the image is not cropping to the original image, in other words, it cannot get a cropped image to original picture..

Migrating from old version

I have your older version of the library and those did not have the mCropView.startCrop and mCropView.startLoad methods. Also i developed it around where I pass the absolute path to the file and load it in the CropImageView bitmap.
Since you have introduced the uri model, is it mandatory to use this?
Its going be quite tough to convert all the logic to uri based.

Question

Hi. Can I get cropped region coordinates?

OutOfMemoryError

When trying to load a camera image from my Galaxy s6, the app force closes.

at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:599)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:724)
at com.shifat.cropandupload.MainActivity.onActivityResult(MainActivity.java:66)
at android.app.Activity.dispatchActivityResult(Activity.java:5192)

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.