Android generates QR code =. And Chinese Garbled text. Android generates Chinese Garbled text

Source: Internet
Author: User

Android generates QR code =. And Chinese Garbled text. Android generates Chinese Garbled text

Reference http://blog.csdn.net/books1958/article/details/46346531

And http://www.cnblogs.com/mythou/p/3280023.html

 

Many articles are old and outdated. After searching for them for a long time, only the two are useful =.

The zing package is 3.1, linked to the following http://pan.baidu.com/s/1pKfkQVp

 

The MainActivity code is as follows:

package com.example.wang.bmap;import com.google.zxing.*;import android.graphics.Bitmap;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import com.google.zxing.common.BitMatrix;import com.google.zxing.qrcode.QRCodeWriter;public class MainActivity extends AppCompatActivity {    private Button genButton;    private ImageView img;    private EditText input;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // ATTENTION: This was auto-generated to implement the App Indexing API.        // See https://g.co/AppIndexing/AndroidStudio for more information.        genButton = (Button)findViewById(R.id.gen);        img = (ImageView)findViewById(R.id.img);        input = (EditText)findViewById(R.id.input);        createQR();    }    public void createQR(){        genButton.setOnClickListener(new View.OnClickListener() {                    public void onClick(View arg0) {                        String in = input.getText().toString();                        try {                            BitMatrix qrcode = new QRCodeWriter().encode(in, BarcodeFormat.QR_CODE, 400, 400);                            int[] pixels = new int[400 * 400];                            for (int y = 0; y < 400; y++) {                                for (int x = 0; x < 400; x++) {                                    if (qrcode.get(x, y)) {                                        pixels[y * 400 + x] = 0xff000000;                                    } else {                                        pixels[y * 400 + x] = 0xffffffff;                                    }                                }                            }                            Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);                            bitmap.setPixels(pixels, 0, 400, 0, 0, 400, 400);                            img.setImageBitmap(bitmap);                        } catch (WriterException e) {                            e.printStackTrace();                        }                    }                }        );    }/**/}

  

Xml Code

<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/plugin" tools: context = "com. example. wang. bmap. mainActivity "> <TextView android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: text =" generate a QR code from the bottom "/> <EditText android: id = "@ + id/input" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_marginTop = "10dp" android: hint = "Enter the text of the QR code to be generated"/> <Button android: id = "@ + id/gen" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_below = "@ + id/input" android: layout_marginTop = "10dp" android: text = "generate QR code"/> <ImageView android: id = "@ + id/img" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ + id/gen" android: layout_centerHorizontal = "true" android: layout_marginTop = "10dp"/> </RelativeLayout>

 

It is probably the sauce purple

 

 

For garbled questions, google will answer all kinds of questions directly. What I use is

 Hashtable hints = new Hashtable();hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");BitMatrix qrcode = new QRCodeWriter().encode(in, BarcodeFormat.QR_CODE, 400, 400,hints);

Effect

Related Article

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.