星空网 > 软件开发 > 操作系统

安卓生成二维码 ==。以及中文乱码问题

参考了http://blog.csdn.net/books1958/article/details/46346531

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

 

很多文章用的都是旧的,过时了,找了半天只有这两个是好用的 ==。

zing包是3.1, 链接如下  http://pan.baidu.com/s/1pKfkQVp

 

MainActivity代码如下

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();            }          }        }    );  }/**/}

  

<?

 

大概是酱紫  

 

 

乱码问题,直接google就各种答案,我采用的是

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

  效果如图

安卓生成二维码 ==。以及中文乱码问题images/loading.gif' data-original="http://images2015.cnblogs.com/blog/739727/201603/739727-20160324093250089-398225681.jpg" />




原标题:安卓生成二维码 ==。以及中文乱码问题

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

伊视跨境电商:https://www.goluckyvip.com/tag/47451.html
伊斯坦布尔海外仓:https://www.goluckyvip.com/tag/47452.html
衣橱节:https://www.goluckyvip.com/tag/47453.html
衣服fba:https://www.goluckyvip.com/tag/47454.html
衣品诚制衣厂:https://www.goluckyvip.com/tag/47455.html
医护服装:https://www.goluckyvip.com/tag/47456.html
美国版权小知识-哪些作品能够登记美国版权?:https://www.kjdsnews.com/a/1836627.html
俄罗斯汽车企业进口东风汽车零部件组装雪铁龙汽车:https://www.kjdsnews.com/a/1836628.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流