Giter Site home page Giter Site logo

clip-image's Introduction

clip-image

仿微信图片裁剪。

仿微信的裁剪控件,拖动图片而裁剪框不动。可设置长宽比例,裁剪边框的边距,遮罩层颜色,提示文字及文字大小等。

##效果演示 裁剪演示

##使用方式

添加依赖

    compile 'com.githang:clipimageview:0.1'

XML代码

    <com.githang.clipimage.ClipImageView
        android:id="@+id/clip_image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom"
        app:civClipPadding="@dimen/padding_common"
        app:civHeight="2"
        app:civMaskColor="@color/viewfinder_mask"
        app:civWidth="3"/>

Java代码

设置图片:

    mClipImageView.setImageBitmap(target);

裁剪图片:

    return mClipImageView.clip();

###直接调用里面的Activity 启动裁剪界面

 ClipImageActivity.prepare()
                    .aspectX(3).aspectY(2)//裁剪框横向及纵向上的比例
                    .inputPath(tempPath).outputPath(mOutput)//要裁剪的图片地址及裁剪后保存的地址
                    .startForResult(this, Const.REQUEST_CLIP_IMAGE);

接收裁剪结果

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK && requestCode == Const.REQUEST_CLIP_IMAGE) {
            String path = ClipImageActivity.ClipOptions.createFromBundle(data).getOutputPath();
            if (path != null) {
                Bitmap bitmap = BitmapFactory.decodeFile(path);
                mImageView.setImageBitmap(bitmap);
            }
            return;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

##大图裁剪 请参考ClipImageActivity类。

##目前支持属性

  • civHeight 高度比例,默认为1
  • civWidth 宽度比例,默认为1
  • civTipText 裁剪的提示文字
  • civTipTextSize 裁剪的提示文字的大小
  • civMaskColor 遮罩层颜色
  • civClipPadding 裁剪框边距

##参考资料

clip-image's People

Contributors

msdx avatar

Watchers

James Cloos 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.