In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use zxing to generate QR code in Android, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will have something to gain after reading this Android article on how to generate QR code using zxing. Let's take a look.
The principle of QR code generation (that is, the working principle)
The QR code is officially called version Version. Version 1 is a matrix of 21 x 21, Version 2 is a matrix of 25 x 25, and Version 3 is the size of 29. Each additional version increases the size of 4. The formula is: (Vmur1) * 4x21 (V is the version number) up to Version 40, (40-1) * 4x21 = 177, so the highest is 177x177square.
Here is an example of a QR code:
The effect picture is as follows:
Premise:
After importing the jar of zxing, the operation begins, and the old rule finally has source code, and the author's layout defaults to the relative layout.
Step 1: define the length, width, height and picture controls of the QR code
Step 2: instantiate the QRCodeWriter and use the for loop to draw the QR code, and then use the picture control to load the picture.
The source code is as follows
Layout file: * *
Java file:
Public class MainActivity extends Activity implements View.OnClickListener {private int width = 300; private int height = 300; private ImageView imageView; private Bitmap bit; private Button mybutton; private EditText myeditText; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); initView ();} private void initView () {imageView = (ImageView) findViewById (R.id.imageView) Mybutton = (Button) findViewById (R.id.mybutton); mybutton.setOnClickListener (this); myeditText = (EditText) findViewById (R.id.myeditText); myeditText.setOnClickListener (this);} @ Override public void onClick (View v) {switch (v.getId ()) {case R.id.mybutton: String name=myeditText.getText (). ToString () If (name.equals (")) {myeditText.setError (" Please enter content ");} else {zxing (name);} break;}} private void zxing (String name) {QRCodeWriter qrCodeWriter = new QRCodeWriter (); Map hints = new HashMap () Hints.put (EncodeHintType.CHARACTER_SET, "utf-8"); / / remember to customize the length and width BitMatrix encode = null; try {encode = qrCodeWriter.encode (name, BarcodeFormat.QR_CODE, width, height, hints);} catch (WriterException e) {e.printStackTrace ();} int [] colors = new int [width * height] / write out for (int I = 0; I < width; iTunes +) {for (int j = 0; j < height; jacks +) {if (encode.get (I, j)) {colors [I * width + j] = Color.BLACK by using the for loop. } else {colors [I * width + j] = Color.WHITE;} bit = Bitmap.createBitmap (colors, width, height, Bitmap.Config.RGB_565); imageView.setImageBitmap (bit) }} this is the end of the article on "how to use zxing to generate QR codes in Android". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use zxing to generate QR codes in Android". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.