首先是简单的编码,代码如下
/**
* 根据字符串进行二维编码
* @param str 需要编码的字符串
* @param widthAndHeight 需要生成的bitmap的高宽
* @return
*/
public Bitmap enCode(String str,int widthAndHeight){
if (!str.equals("")&&str!=null)
try {
return EncodingHandler.createQRCode(str, widthAndHeight);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else
try {
return EncodingHandler.createQRCode("null", widthAndHeight);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
再次,是简单的解码,代码如下
public String deCode(Bitmap bitmap) {
if(bitmap ==null){
Log.i("deCode","-----------------------null");
return "null";
}
Hashtable<DecodeHintType, Ob