Powerful image capture pruning artifact: A brief analysis of Android Simplecropview and its instance code reuse

Source: Internet
Author: User

Powerful image capture pruning artifact: A brief analysis of Android Simplecropview and its instance code reuse


Simplecropview is the first third-party open source image pruning tool on GitHub, powerful and well designed. I personally think that Simplecropview is more powerful and complete than the Cropper described in Appendix 1, but also more complex, if it is a simple application scenario, then Cropper is also a good choice, simplecropview to adapt to the image clipping to intercept complex requirements tasks.
Simplecropview on GitHub on the project homepage is: Https://github.com/IsseiAoki/SimpleCropView


Simplecropview provides a very rich picture clipping function, covering commonly used basic requirements functions, the chip's proportional interception (4:3,16:9,7:5 and so on), interception into a circle, free cropping, locking proportional cropping, square clipping and so on.
Perhaps because the Simplecropview function is powerful, complete, so the code involved is not simple, simplecropview on GitHub gives the instance code as a whole relatively complete, tight coupling, more difficult to decouple. However, simplecropview the instance Code project as a complete component, careful analysis can see the code to run the context, the Simplecropview on the project code a little adjustment, you can completely take it for their own use, but need to clear code running mechanism.
Here the main note simplecropview the code to run the mechanism, clear these, later I if I use, can be used to modify the use.
Simplecropview in the instance code is run from Mainactivity, the mainactivity has two functions: (1) load a framelayout, it is clear that this is an empty, for subsequent loading fragment "bed" to do container preparation.
(2) There is an activity called Resultactivity.java in the Mainactivity code, and this resultactivity will be our focus in our project. Mainactivity is actually not very important, its meaning is to provide a code to run the portal.
Mainactivity finally introduces the code to the core of the processing picture: Mainfragment.java. It can be said that the basic piece of processing work is carried out in the mainfragment inside.
If you want to use this mainfragment in your project, then Mainfragment will be a ready-made picture modification editor, all you have to do is modify the style, Or, in Mainfragment's static method getinstance, pass in a ready-to-process picture resource as a parameter.
Finally through the mainfragment processing (clipping, pruning, interception) of the picture will be passed through the form of a URI into the resultactivity inside, Resultactivity, as the name implies, the result activity! The result of the image processing is within the resultactivity. In a thread run, it is eventually set to the developer-specified final destination, such as a imageview avatar.
Heuristic: If I'm not going to do a larger-than-deep decoupling of the instance code given by Simplecropview, we can focus on the Resultactivity class.
For example, suppose a development scenario where the avatar in a page is free to select and crop, and in this page the user clicks on the avatar to intercept and clip the avatar, then I can consider doing this:
(1) Start mainactivity (of course, in your own project, usually change the name of the activity to a generic name instead of main) and pass in the image we need to crop.
(2) Pass a picture resource as a parameter to Mainfragment while entering mainfragment from Mainactivity. The result of the mainfragment inside processing is automatically entered into the ImageView of resultactivity with an ID of result_image.

The above is the basic process, then if we want to use Simplecropview written code in our own project, then we can transform the instance code given by Simplecropview, Suppose I write my own project in a fragment or activity in one of the Avatar, the avatar can be clicked, click to enter the editor avatar. So do that, after clicking into the Simplecropview in the mainactivity, Mainfragment-resultavtivity (Note this process, you need to pass the picture as a parameter, if the picture is a user selection, Then remove the reference), finally in the resultavtivity in the internal thread class Loadscaledimagetask run inside to get processing results bitmap Sampledbitmap, this bitmap Sampledbitmap is what we end up needing, the cut-off picture:

After getting this result bitmap, it was a big success, and the code behind it could take many forms to advertise to my own source of demand in my project. As for the form of announcements can be varied, such as broadcasting, third-party open source communication, writing files and so on.


Appendix Article:
1, "Android third party open source image clipping interception: Cropper" link address: http://blog.csdn.net/zhangphil/article/details/51644396
2, "Android set avatar, mobile photos or choose pictures from local albums as Avatar" link address: http://blog.csdn.net/zhangphil/article/details/44829747

Transferred from: http://blog.csdn.net/zhangphil/article/details/51655275

Powerful image capture pruning artifact: An analysis of Android Simplecropview and its instance code reuse (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.