Home  >  Article  >  Backend Development  >  Image cropping function development example

Image cropping function development example

小云云
小云云Original
2018-03-12 13:58:131393browse

. Enable users to save the payment QR code of WeChat, Alipay and other applications to achieve quick payment function. Implementing this function requires image cropping, image saving, file reading and other technologies. The difficulty is how to realize the user's selected Cut out the QR code you need to use from the picture. I downloaded lib-cropview on GIT to be lazy. Here is how to use this library.

1. Click the project address to open the link

2. Use the method that needs to add the Model (1. Add the Model, 2. Associate the model in gradle

compile project(path: ':lib-cropview'))
<activity android:name="com.jeanboy.cropview.cropper.CropActivity"
            android:theme="@style/AppTheme.NoActionBar"/>
<br>

4. In the call Activity implements CropHandle method

@Override
    public Activity getActivity() {        return this;
    }    @Override
    public CropperParams getParams() {        //配置裁切框比例
        return new CropperParams(1, 1);        //不约束裁切比例
        // return new CropperParams(0, 0);
    }    @Override
    public void onCropped(Uri uri) {        Log.d("=====onCropped======", "======裁切成功=======" + uri);
    }    @Override
    public void onCropCancel() {        Log.d("=====onCropCancel====", "======裁切取消=====");
    }    @Override
    public void onCropFailed(String msg) {        Log.d("=====onCropFailed===", "=======裁切失败======" + msg);
    }

5. Initialize Crop Manage

	@Override
    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        CropperManager.getInstance().build(this);
    } 	@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        super.onActivityResult(requestCode, resultCode, data);        CropperManager.getInstance().handlerResult(requestCode, resultCode, data);
    }
  • Calling operation

  CropperManager.getInstance().pickFromCamera();//拍照裁切
  CropperManager.getInstance().pickFromGallery();//图库选择裁切

Notes

CropActivity does not require ActionBar

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <!-- 关闭ActionBar -->
    <item name="windowActionBar">false</item>
    <!-- 隐藏title -->
    <item name="windowNoTitle">true</item></style>

The image cropping function is now completed

Related recommendations:

jquery implements custom image cropping function code sharing

Detailed explanation about CSS3 multiple backgrounds and background image cropping, positioning and size

PHP image cropping and scaling example (lossless cropping of images)

The above is the detailed content of Image cropping function development example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn