Image cropping function development example

小云云
Release: 2023-03-21 08:48:01
Original
1335 people have browsed it

. 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 downloadedlib-cropviewon 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'))
Copy after login
Copy after login

Copy after login

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); }
Copy after login

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); }
Copy after login
  • Calling operation

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

Notes

CropActivity does not require ActionBar

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!