編輯:關於android開發
參考了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(); } } } ); } /* */ }
xml代碼
<?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/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.wang.bmap.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="從下邊生成二維碼" /> <EditText android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:hint="請輸入要生成的二維碼文字" /> <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="生成二維碼" /> <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>
大概是醬紫
亂碼問題,直接google就各種答案,我采用的是
Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix qrcode = new QRCodeWriter().encode(in, BarcodeFormat.QR_CODE, 400, 400,hints);
效果如圖
單機搭建Android開發環境(二),單機搭建android開發 前文介紹了如何優化SSD和內存,以發揮開發主機的最佳性能,
安卓應用的界面編程(5),安卓界面編程第四組UI組件:AdapterView及其子類 AdapterView組件是一組重要的組件,Adapte
Android IPC 之 AIDL(一) IPC是Inter-Process Communication的縮寫,即跨進程通信。Android中跨進程通信有多種方式,如文
A DB2 Performance Tuning Roadmap--Q-BASED A/A IMPLEMENATIONWhy Active/Active ? - Bus