解决方案 »

  1.   

    ----------------------------根据输入字符串生成图片
    public final class EncodingHandler {
    private static final int BLACK = 0xff000000;

    public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();  
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
    BitMatrix matrix = new MultiFormatWriter().encode(str,
    BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];

    for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
    if (matrix.get(x, y)) {
    pixels[y * width + x] = BLACK;
    }
    }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
    Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
    }
    ---------------保存你的bitmap
    /** 保存方法 */
     public void saveBitmap() {
      Log.e(TAG, "保存图片");
      File f = new File("/sdcard/namecard/", picName);
      if (f.exists()) {
       f.delete();
      }
      try {
       FileOutputStream out = new FileOutputStream(f);
       //bm 就是你的bitmap 图对象,用输出流
       bm.compress(Bitmap.CompressFormat.PNG, 90, out);
       out.flush();
       out.close();
       Log.i(TAG, "已经保存");
      } catch (FileNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } }
    -----------------------------------------------
    兄弟已经放到了嘴边,最近 都没有分数了。给分了。记得!
     在这里还需要两个权限:    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>