Method for Android to obtain QR code from picture

In my previous blog, I remember talking about scanning QR code. Yesterday, the team leader asked me not only to scan and obtain QR code, but also to obtain the QR code through pictures. For example, if someone takes a QR code photo and sends it to you, the app should be able to obtain the QR code of the picture.

I checked the information on the Internet and found that it is actually very simple. I can basically use the qrcodereader for obtaining the picture QR code in the zxing jar package. However, I don't understand most of the content. If you are interested, you can find the information yourself.

1. Click the button, jump to the photo album, select the picture with QR code, and return to the interface of parsing QR code. At this time, the path of the image is obtained through the returned URI.

This is through ContentResolver query URI to get the path of the picture, and then call parseQRcodeBitmap (imgPath) to get the two-dimensional code of the picture.

2. Analyze the picture through the picture path to obtain the QR code value of the picture.

Here, first obtain the bitmap of the picture. You need to set the obtained bitmap to a certain size through options.insamplesize, and then

Convert the two-dimensional code of bitmap into a picture, and then convert the picture into a binary picture, and call the result = reader.decode (binarybitmap, hints) of qrcodereader; The code converts the binary image into a QR code, and then directly obtains the string of the return value, which is the QR code value.

A user-defined class rgbloomancesource is used. Its main function is to obtain the two-dimensional code content of the picture and filter the content except the two-dimensional code to facilitate the subsequent analysis of the two-dimensional code.

In this way, you can identify the QR code of the picture. You must first import the zxing jar package with this function. This is very simple. There are many introductions on the Internet. You can find it yourself.

That's all for Android to get the QR code from the picture.

It's that simple.

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