The first is simple coding, the code is as follows
/**
* Two-dimensional encoding based on strings *
@param str needs to encode the string
* @param widthandheight the height of the bitmap that needs to be generated
@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) { c19/>//TODO auto-generated Catch block
e.printstacktrace ();
}
return null;
}
Again, is the simple decoding of the code as follows
Public String DeCode (Bitmap Bitmap) {if (Bitmap ==null) {log.i ("DeCode", "-----------------------null");
return "NULL";
} hashtable<decodehinttype, object> hints = null;
Inithints (hints, NULL, "UTF8");
Multiformatreader Multiformatreader = new Multiformatreader ();
Multiformatreader.sethints (hints);
Luminancesource Source = new Bitmapluance (bitmap);
Binarybitmap bit = new Binarybitmap (new Hybridbinarizer (source));
try {return multiformatreader.decodewithstate (bit). GetText ();
The catch (Readerexception re) {//Continue} finally {Multiformatreader.reset ();
return null; } public void Inithints (Hashtable<decodehinttype, object> hints, vector<barcodeformat> decodeFormats, STR
ing code_style) {hints = new Hashtable<decodehinttype, object> (2);
if (decodeformats = null | | decodeformats.isempty ()) {decodeformats = new vector<barcodeformat> (); Decodeformats.addall (mydecodeformatmanager.one_d_forMATS);
Decodeformats.addall (Mydecodeformatmanager.qr_code_formats);
Decodeformats.addall (Mydecodeformatmanager.data_matrix_formats);
} hints.put (Decodehinttype.possible_formats, decodeformats);
if (Code_style!= null) {//hints.put (Decodehinttype.character_set, Code_style);
} private Bitmap Filetobitmap (String imgpath) {Bitmap BM = bitmapfactory.decodefile (Imgpath);
return BM; }
Click here to download the sample source code