Android develops imitation scanning to realize the photo function in the shooting frame

It is modeled on the current scanning form, surrounded by translucent shielding, and then fully transparent in the middle. After shooting, only the contents in the frame are intercepted

Checked a lot of blogs, the implementation is really too complicated. I'm afraid of trouble, so I'm lazy in many places

Effect drawing first:

Step 1: set camera preview and take photos

This is the premise of all steps. Without preview, how can users know what they are shooting. The preview uses surfaceview

This blog post has been written in great detail. Turn on the camera and take pictures. It's very concise! I don't want to be confused with hundreds of lines of code on other blogs. This code can be copied and used as a camera template.

A problem encountered here is that the preview effect is to turn left 90 degrees, and the shot is also to turn left 90 degrees. After checking a lot of data, we have a unified approach. Set the right rotation 90 degrees in the camera preview, and then rotate the photos 90 degrees. I'll post the code for the specific method

Step 2: set translucent border

Many blogs are too responsible for drawing.

In fact, if you consider simplicity, just overlay a layer of pictures on the surface view and use the FrameLayout layout

The background is translucent, with the middle button off

Step 3: how to only take pictures in the frame

Many blogs talk at length about this problem. They use all matrix operations. Although they are very strong, they don't want to see it.

Take a picture in the frame, take a complete picture directly, and then dig in the picture.

Bitmap. createBitmap(bitmap,50,250,650,500);

Calculate the position of the transparent frame, the coordinates of the upper left corner, and the width and height. With the above function, you can matting in the original photo.

Step 4: improve it and add click focus

In fact, just call the focus function in the click event

Total code:

The above is what Xiaobian introduced to you. Android development imitates scanning to realize the photo function in the shooting box. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>