Android implements image clipping (does not call system functions)

Follow the previous article: Android implements the image region clipping function

The previous article mentioned that the zoom / cropping of pictures can be realized by calling the system photo album or taking pictures. However, this is also not suitable for the requirements of the author's project. What the author needs is to take a screenshot of the whole mobile phone screen and cut the screenshot.

Depending on the system function, you can really cut the picture, but it is not flexible enough. Here the author provides a more flexible approach.

However, the user experience of this approach is not as good as that of the previous article. As for what method to use, readers should measure it by themselves.

Similarly, let's look at the actual renderings first.

Here is a small part of the author's project (Reader):

We click the cut button in the lower left corner

We use the four corners of the red border to control the size of the clipping, and move the red box to control the position area of the clipping.

Next, let's look at the implementation of the source code:

First, when clicking the cut button, we should generate a bitmap object and pass it to another activity for processing

The specific methods are as follows:

Tips: here, the author passes the intercepted bitmap object to another activity for related processing. Here, how to pass the bitmap between activities? Here we simply use the Java syntax features to complete it. The specific methods are as follows:

We have a public static Bitmap bitmap object in actvitya. When activitya jumps to B, we directly obtain this object through activitya.bitmap.

Then there is how to cut. The operation is performed in another activity. The XML configuration file information is as follows:

Through the configuration file, we can see that we have customized a view (ImageView), which is implemented as follows:

Next, let's look directly at the source code of activity:

OK, it can be realized without relying on the simple cutting function of the system. Here, the author will not give the source code download. The above code readers can use it as long as they change it themselves.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>