Knowledge about QR code scanning and Scanning

Source: Internet
Author: User

Knowledge about QR code scanning and Scanning

1. QR code scanning

A QR code is a bar code image that uses black and white plane ry to record text, images, URLs, and other information through the corresponding encoding algorithm. For example

Features of the QR code:

1. High-density coding, large information capacity

It can contain up to 1850 uppercase letters, 2710 numbers, 1108 bytes, or more than 500 Chinese characters, which is about dozens of times higher than the normal bar code information.

2. Wide encoding range

This bar code can encode pictures, sounds, text, signatures, fingerprints, and other digital information, which can be represented by a bar code. It can represent texts in multiple languages and image data.

3. Strong fault tolerance and Error Correction

This makes the two-dimensional bar code due to perforation, fouling, and other causes of local damage, still can be correctly read, the damaged area of up to 50% still can restore information.

4. High decoding Reliability

It is much lower than the error rate of normal bar code decoding, and the error rate cannot exceed one thousandth of a thousand.

5. encryption measures can be introduced

Good confidentiality and anti-counterfeiting.

6. low cost, easy to make, and durable

Because of these features, QR codes are becoming increasingly popular and widely used. (For more information, see Baidu encyclopedia. This article is not the focus, this blog post will show you how to generate and parse the QR code.

 

Jar package: QRCode. jar

Http://download.csdn.net/detail/wangpeng047/4008532

TwoDimensionCode class: QR code operation core class

1 package qrcode; 2 3 import java. awt. color; 4 import java. awt. graphics2D; 5 import java. awt. image. bufferedImage; 6 import java. io. file; 7 import java. io. IOException; 8 import java. io. inputStream; 9 import java. io. outputStream; 10 11 import javax. imageio. imageIO; 12 13 import jp. sourceforge. qrcode. QRCodeDecoder; 14 import jp. sourceforge. qrcode. exception. decodingFailedException; 15 16 import com. swe Take. util. qrcode; 17 18 public class TwoDimensionCode {19 20/** 21 * generate a QR code (QRCode) image 22 * @ param content storage content 23 * @ param imgPath image path 24 */25 public void encoderQRCode (String content, String imgPath) {26 this. encoderQRCode (content, imgPath, "png", 7); 27} 28 29/** 30 * generate a QR code (QRCode) image 31 * @ param content 32 * @ param output stream 33 */34 public void encoderQRCode (String content, OutputSt Ream output) {35 this. encoderQRCode (content, output, "png", 7); 36} 37 38/** 39 * generate a QR code (QRCode) image 40 * @ param content storage content 41 * @ param imgPath image path 42 * @ param imgType image type 43 */44 public void encoderQRCode (String content, String imgPath, String imgType) {45 this. encoderQRCode (content, imgPath, imgType, 7); 46} 47 48/** 49 * generate a QR code (QRCode) image 50 * @ param content storage content 51 * @ param output stream 52 * @ Param imgType: Image type 53 */54 public void encoderQRCode (String content, OutputStream output, String imgType) {55 this. encoderQRCode (content, output, imgType, 7); 56} 57 58/** 59 * generate a QR code (QRCode) image 60 * @ param content storage content 61 * @ param imgPath image path 62 * @ param imgType image type 63 * @ param size QR code size 64 */65 public void encoderQRCode (String content, string imgPath, String imgType, int size) {66 try {67 BufferedImage bufImg = this. qRCodeCommon (content, imgType, size); 68 69 File imgFile = new File (imgPath); 70 // generate a QR code QRCode image 71 ImageIO. write (bufImg, imgType, imgFile); 72} catch (Exception e) {73 e. printStackTrace (); 74} 75} 76 77/** 78 * generate a QR code (QRCode) image 79 * @ param content storage content 80 * @ param output stream 81 * @ param imgType image type 82 * @ param size QR code size 83 */84 public void encoderQRCode (S Tring content, OutputStream output, String imgType, int size) {85 try {86 BufferedImage bufImg = this. qRCodeCommon (content, imgType, size); 87 // generate a QR code QRCode image 88 ImageIO. write (bufImg, imgType, output); 89} catch (Exception e) {90 e. printStackTrace (); 91} 92} 93 94/** 95 * generate a QR code (QRCode) image public Method 96 * @ param content storage content 97 * @ param imgType Image Type 98 * @ param size QR code size 99 * @ return 100 */101 p Rivate BufferedImage qRCodeCommon (String content, String imgType, int size) {102 BufferedImage bufImg = null; 103 try {104 Qrcode qrcodeHandler = new Qrcode (); 105 // set the error rate of the QR code, optional L (7%), M (15%), Q (25%), H (30%), the higher the error rate, the less information that can be stored, however, the smaller the requirement for two-dimensional code definition is, the smaller the 106 qrcodeHandler. setQrcodeErrorCorrect ('M'); 107 qrcodeHandler. setQrcodeEncodeMode ('B'); 108 // set the two-dimensional code size. The value range is 1-40. The larger the value is, the larger the size is. The greater the information that can be stored, the greater the 109 qrcodeHandler. setQrcodeVersi On (size); 110 // The byte array of the obtained content. Set the encoding format to 111 byte [] contentBytes = content. getBytes ("UTF-8"); 112 // image size 113 int imgSize = 67 + 12 * (size-1); 114 bufImg = new BufferedImage (imgSize, imgSize, BufferedImage. TYPE_INT_RGB); 115 Graphics2D gs = bufImg. createGraphics (); 116 // set the background color to 117 gs. setBackground (Color. WHITE); 118 gs. clearRect (0, 0, imgSize, imgSize); 119 120 // sets the image color> BLACK 121 gs. setColor (Color. BLACK); 122 // set the offset. if this parameter is not set, the parsing error may be 123 int pixoff = 2. 124 // output content> QR code 125 if (contentBytes. length> 0 & contentBytes. length <800) {126 boolean [] [] codeOut = qrcodeHandler. calQrcode (contentBytes); 127 for (int I = 0; I <codeOut. length; I ++) {128 for (int j = 0; j <codeOut. length; j ++) {129 if (codeOut [j] [I]) {130 gs. fillRect (j * 3 + pixoff, I * 3 + pixoff, 3, 3); 131} 132} 133} els E {135 throw new Exception ("QRCode content bytes length =" + contentBytes. length + "not in [0,800]. "); 136} 137 gs. dispose (); 138 bufImg. flush (); 139} catch (Exception e) {140 e. printStackTrace (); 141} 142 return bufImg; 143} 144 145/** 146 * parse QR code (QRCode) 147 * @ param imgPath image path 148 * @ return 149 */150 public String decoderQRCode (String imgPath) {151 // QRCode QR code image File 152 File imag EFile = new File (imgPath); 153 BufferedImage bufImg = null; 154 String content = null; 155 try {156 bufImg = ImageIO. read (imageFile); 157 QRCodeDecoder decoder = new QRCodeDecoder (); 158 content = new String (decoder. decode (new TwoDimensionCodeImage (bufImg), "UTF-8"); 159} catch (IOException e) {160 System. out. println ("Error:" + e. getMessage (); 161 e. printStackTrace (); 162} catch (DecodingFa IledException dfe) {163 System. out. println ("Error:" + dfe. getMessage (); 164 dfe. printStackTrace (); 165} 166 return content; 167} 168 169/** 170 * parse QR code (QRCode) 171 * @ param input stream 172 * @ return 173 */174 public String decoderQRCode (InputStream input) {175 BufferedImage bufImg = null; 176 String content = null; 177 try {178 bufImg = ImageIO. read (input); 179 QRCodeDecoder decoder = new Q RCodeDecoder (); 180 content = new String (decoder. decode (new TwoDimensionCodeImage (bufImg), "UTF-8"); 181} catch (IOException e) {182 System. out. println ("Error:" + e. getMessage (); 183 e. printStackTrace (); 184} catch (DecodingFailedException dfe) {185 System. out. println ("Error:" + dfe. getMessage (); 186 dfe. printStackTrace (); 187} 188 return content; 189} 190 191 public static void main (St Ring [] args) {192 String imgPath = "G:/TDDOWNLOAD/Michael_QRCode.png"; 193 String encoderContent = "Hello, big, small, welcome to QRCode! "+" \ NMyblog [http://sjsky.iteye.com] "+" \ nEMail [sjsky007@gmail.com] "; 194 TwoDimensionCode handler = new TwoDimensionCode (); 195 handler. encoderQRCode (encoderContent, imgPath, "png"); 196 // try {197 // OutputStream output = new FileOutputStream (imgPath); 198 // handler. encoderQRCode (content, output); 199 //} catch (Exception e) {200 // e. printStackTrace (); 201 //} 202 System. out. printl N ("======== encoder success"); 203 204 205 String decoderContent = handler. decoderQRCode (imgPath); 206 System. out. println ("Resolution Result:"); 207 System. out. println (decoderContent); 208 System. out. println ("========= decoder success !!! "); 209} 210}

TwoDimensionCodeImage class: QR code image object

 1 package qrcode;   2    3 import java.awt.image.BufferedImage;   4    5 import jp.sourceforge.qrcode.data.QRCodeImage;   6    7 public class TwoDimensionCodeImage implements QRCodeImage {   8    9     BufferedImage bufImg;  10       11     public TwoDimensionCodeImage(BufferedImage bufImg) {  12         this.bufImg = bufImg;  13     }  14       15     @Override  16     public int getHeight() {  17         return bufImg.getHeight();  18     }  19   20     @Override  21     public int getPixel(int x, int y) {  22         return bufImg.getRGB(x, y);  23     }  24   25     @Override  26     public int getWidth() {  27         return bufImg.getWidth();  28     }  29   30 }  

 


Is there any built-in QR code scanning software in oppo R807?

You can install "I checked" software on your own, and scan and identify the QR code and QR code of the product.

How to scan QR codes

I want to know... you first download a QR code scanning software from your mobile phone, and then open the software to align the camera with the QR code you want to scan (the QR code diagram should be in the box of the scanning software ), the mobile phone will automatically...

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.