Giter VIP home page Giter VIP logo

cropme's Introduction

CropMe

Gradle

dependencies {
    implementation 'com.github.takusemba:cropme:x.x.x'
}

Usage

Build Status Download License API

This is an Android library for cropping images. Move images smoothly, and crop images precisely.

Use CropView in your xml file.

  <com.takusemba.cropme.CropLayout
    android:id="@+id/crop_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cropme_background_alpha="80%"
    app:cropme_frame_height_percent="80%"
    app:cropme_frame_width_percent="80%"
    app:cropme_max_scale="2.0"
    app:cropme_overlay_shape="rectangle"
    app:cropme_with_border="true"
    >

Set your image

cropView.setUri(uri);
// or
cropView.setBitmap(bitmap)

Crop it!

cropLayout.addOnCropListener(object : OnCropListener {
  override fun onSuccess(bitmap: Bitmap) {
    // do somethhing with bitmap.
  }

  override fun onFailure(e: Exception) {
    // do error handling.
  }
})
    
cropView.isOffFrame() // optionally check if the image is off the frame.

cropView.crop() // crop image

Attributes

attribute description default
cropme_frame_width_percent width of croppling frame 80%
cropme_frame_height_percent height of croppling frame 80%
cropme_max_scale maximum scale while cropping 2.0
cropme_with_border if borders are shown while cropping true
cropme_background_alpha background alpha out side of cropping area 80%
cropme_overlay_shape shape of croppling frame rectangle / circle / custom
cropme_custom_shape_layout custom layout for custom shape @layout/custom_layout

Custom Overlay

If you want to show a custom overlay, you can customize the Overlay by extending CropOverlay.

You can see more detail in app module.

class CustomCropOverlay @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    cropOverlayAttrs: AttributeSet? = attrs
) : CropOverlay(context, attrs, defStyleAttr, cropOverlayAttrs) {

  override fun drawBackground(canvas: Canvas, paint: Paint) {
    // draw background
  }

  override fun drawCrop(canvas: Canvas, paint: Paint) {
    // draw croppling frame
  }

  override fun drawBorder(canvas: Canvas, paint: Paint) {
    // draw borders
  }
}

Sample

Clone this repo and check out the app module.

Author

Licence

Copyright 2017 Taku Semba.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License 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.

cropme's People

Contributors

nicobos avatar takahirom avatar takusemba 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

cropme's Issues

Grid Resize?

Hi,thanks for such helpful library , i have been using it for Cropping images with jetpack compose. I have question whether it's possible to resize/move the GRID ?

horizontalで写真が表示させています

Verticalで写真撮った後、cropviewはhorizontalの写真が表示されています。
現時点はVerticalで写真が表示させたいんです。

修正方がありますでしょうか。

Gradle Sync issue

FAILURE: Build failed with an exception.

* Where:
Script 'D:\Development\AndroidStudioProjects\CropMe\publish.gradle' line: 83

* What went wrong:
A problem occurred configuring project ':cropme'.
> Could not get unknown property 'sonatypeUsername' for Credentials [username: null] of type org.gradle.internal.credentials.DefaultPasswordCredentials_Decorated.

Use original image dimensions

The library shrinks the image down to the screen resolution (for example, if the original resolution is 16 megapixels and the screen is 1080x1920, the result will be no larger than 1080x1920 regardless of the scaling factor), which is not always the desired behavior. It would be great to add the ability to crop an image based on the dimensions of the original image.

transparency issue in overlay

In CropOverlay.kt,

backgroundAlpha = a.getFraction(
            R.styleable.CropLayout_cropme_background_alpha,
                DEFAULT_BASE,
                DEFAULT_PBASE,
                DEFAULT_BACKGROUND_ALPHA
        ) * COLOR_DENSITY

should be

backgroundAlpha = a.getFraction(
            R.styleable.CropLayout_cropme_background_alpha,
                DEFAULT_BASE,
                DEFAULT_PBASE,
                DEFAULT_BACKGROUND_ALPHA
        )

isOffFrame goes true when fully zoomed out

The flag isOffFrame() returns true sometimes when the image is fully zoomed out. The box is still containing the part of image and I don't see the frame going off the image. Why is this happening?

My xml code:

<com.takusemba.cropme.CropLayout
        android:id="@+id/pvImage"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="@dimen/screen_horizontal_margin"
        android:background="@color/colorBlack"
        android:src="@drawable/bg_splash"
        app:cropme_background_alpha="80%"
        app:cropme_frame_height_percent="75%"
        app:cropme_frame_width_percent="75%"
        app:cropme_max_scale="2.0"
        app:cropme_overlay_shape="rectangle"
        app:cropme_with_border="true"
        app:layout_constraintBottom_toTopOf="@id/btnChangePhoto"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tvHeading" />

Feature request: Just export crop rectangle

Heyhey, nice library.

Would it be possible to just export the cropped rectangle bounds,
and set these as initial bound?

the use-case would be to let users manipulate the bounds of a picture. Save this, but then also adust this again later on.

Looking forward to your reply :)
JW

How to crop to square from not square image?

Thank you for great library 🥇

I'am trying to crop a image to square from not square image.
But cropme_result_width(height) attribute only accept percent.
How can I specify cropme_result_width (height) using dp or px?

Fatal Exception: java.lang.IllegalArgumentException: cannot use a recycled source in createBitmap

Hello. I got this report from Firebase and it's from one of our users. Could you check it, please?

Fatal Exception: java.lang.IllegalArgumentException: cannot use a recycled source in createBitmap
at android.graphics.Bitmap.createBitmap(Bitmap.java:882)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:807)
at com.takusemba.cropme.CropLayout$crop$1.invoke(CropLayout.kt:189)
at com.takusemba.cropme.CropLayout$crop$1.invoke(CropLayout.kt:32)
at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)

Out of Memory crash

When repeat crop

OOM crash shows up

Device : LG G4
Android 6.0

01-17 01:34:39.052 32582-811/com.takusemba.cropmesample E/AndroidRuntime: FATAL EXCEPTION: Thread-211226
    Process: com.takusemba.cropmesample, PID: 32582
    java.lang.OutOfMemoryError: Failed to allocate a 193981996 byte allocation with 18563792 free bytes and 17MB until OOM
        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:831)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:739)
        at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:615)
        at com.takusemba.cropme.CropLayout$crop$1.invoke(CropLayout.kt:188)
        at com.takusemba.cropme.CropLayout$crop$1.invoke(CropLayout.kt:31)
        at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
01-17 01:34:39.778 32582-32582/com.takusemba.cropmesample E/WindowManager: android.view.WindowLeaked: Activity com.takusemba.cropmesample.ui.activities.CropActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{afcc6bc V.E...... R.....I. 0,0-1368,1582} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:375)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
        at android.app.Dialog.show(Dialog.java:322)
        at androidx.appcompat.app.AlertDialog$Builder.show(AlertDialog.java:1007)
        at com.takusemba.cropmesample.ui.activities.CropActivity$onCreate$2.onSuccess(CropActivity.kt:58)
        at com.takusemba.cropme.CropLayout$crop$1$1.run(CropLayout.kt:197)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5525)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
01-17 01:34:39.779 32582-32582/com.takusemba.cropmesample E/WindowManager: android.view.WindowLeaked: Activity com.takusemba.cropmesample.ui.activities.CropActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{3961645 V.E...... R.....ID 0,0-1368,0} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:375)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
        at android.app.Dialog.show(Dialog.java:322)
        at androidx.appcompat.app.AlertDialog$Builder.show(AlertDialog.java:1007)
        at com.takusemba.cropmesample.ui.activities.CropActivity$onCreate$2.onSuccess(CropActivity.kt:58)
        at com.takusemba.cropme.CropLayout$crop$1$1.run(CropLayout.kt:197)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5525)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

Crash On Samsung Device

Whenever I call croperview.crop, I am getting this error in Samsung device. I have tested the same code with few more device , its working fine.

FATAL EXCEPTION: main
Process: PID: 1276
java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
at android.graphics.Bitmap.createBitmap(Bitmap.java:793)
at com.takusemba.cropme.CropView.crop(CropView.java:240)
at .Views.Activity.CropperActivity.onCrop(CropperActivity.java:44)
at .Views.Activity.CropperActivity_ViewBinding$1.doClick(CropperActivity_ViewBinding.java:33)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
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:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Image Doesn't show up, using API level 26

I have tried with Oreo configuration, but image doesn't visible when Uri or Bitmap is set to CropView.
On trying with Bitmap it throws an exception, file not found.

Issue with circle crop

I have use app:cropme_overlay_shape="circle" but result is very zoom (Not the same with preview on crop screen)

Image Orientation

When i attach portrait image either from camera/gallery. into crop View it shows landscape image....
how to solve this ? tested on Samsung Galaxy s5.

Images didn't appeared on Samsung A5 (4.4 KitKat -API 19-)

when I try to select image from gallery (camera folder) or take picture, the image did not appears on CropLayout, it always blank,
I tried on the three library versions(2.0.5, 2.0.6, 2.0.7)
please notice: that if choose any other image that I downloaded from chrome or any other image that not taken by camera in general, it worked fine
I also debugged my code it select the correct path (the selected image uri from gallery not empty)
and it set by "setUri" but the image didn't appears on the "CropLayout"

note I also tried setBitmap(bitmap)

I also downloaded your sample application and it work perfect on S7edge( 8.0 Oreo -API 26-) but not on A5

NLP

Process: com.allcode.palacio, PID: 12452
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.allcode.palacio/com.allcode.palacio.activities.newDesigns.ImageCroppingActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.takusemba.cropme.CropLayout.setUri(CropLayout.java:142)
at com.allcode.palacio.activities.newDesigns.ImageCroppingActivity.initViews(ImageCroppingActivity.java:36)
at com.allcode.palacio.activities.newDesigns.ImageCroppingActivity.onCreate(ImageCroppingActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5653) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
06-03 19:38:23.198 12452-12557/com.allcode.palacio E/HttpRestService: CustomParser not found

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.