Coder Social home page Coder Social logo

morristech / instacropper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yasharpm/instacropper

0.0 1.0 0.0 113 KB

A View for cropping images that is similar to Instagram's crop which allows a range of aspect ratios instead of a solid ratio. Also an Activity for cropping is included.

Java 100.00%

instacropper's Introduction

InstaCropper

A View for cropping images that is similar to Instagram's crop. Also an Activity for cropping is included.

alt tag

##Usage

Add the dependency:

dependencies {
	compile 'com.yashoid:instacropper:1.0.3'
}

How to use this library

Add InstaCropperView to your xml layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.yashoid.instacropper.InstaCropperView
        android:id="@+id/instacropper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:backgroundColor="@android:color/white" />

</FrameLayout>

InstaCropperView receives only Uri but any Uri is possible.

mInstaCropper.setImageUri(imageUri);

You can specify three size ratios for the crop. The narrowest allowed, the widest allowed and the ideal ratio. The View will adjust its size by the ideal ratio.

mInstaCropper.setRatios(defaultRatio, minimumRatio, maximumRatio);

The cropped image is returned in a callback. You can specify MeasureSpec to adjust the width and height of the returned Bitmap.

mInstaCropper.crop(
        View.MeasureSpec.makeMeasureSpec(1024, View.MeasureSpec.AT_MOST),
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        new InstaCropperView.BitmapCallback() {

            @Override
            public void onBitmapReady(Bitmap bitmap) {
                // Do something.
            }
            
        }
);

It is also possible to use the crop feature via an Intent call. There are various getIntent() methods defined on InstaCropperActivity. You will then receive the crop result in data.getData().

Intent intent = InstaCropperActivity.getIntent(context, srcUri, dstUri, maxWidth, outputQuality);
startActivityForResult(intent, REQUEST_CROP);

You can modify the crop Activity's apprearance by overriding the following resouce values:

<string name="instacropper_title">Crop</string> <!-- Title of toolbar -->
<string name="instacropper_crop">Crop</string> <!-- Title of crop action in toolbar -->

<color name="instacropper_cropper_background">@android:color/white</color> <!-- Background color of InstaCropperView in the activity -->
<color name="instacropper_crop_color">@android:color/black</color> <!-- Color of crop action in toolbar -->

<style name="InstaCropper" parent="android:style/Theme.DeviceDefault.Light"/> <!-- Style of crop Activity -->

instacropper's People

Contributors

yasharpm avatar

Watchers

 avatar

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.