コード例 #1
0
 private Bitmap putBitmap(String imagePath) {
   Bitmap bitmap = null;
   bitmap = BitmapUtils.compressPictureFromFile(imagePath);
   map.put(imagePath, new SoftReference<Bitmap>(bitmap));
   return bitmap;
 }
コード例 #2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Cursor cursor = null;
    try {
      if (requestCode == GloableUtils.RESULT_PICK_PHOTO_NORMAL && data != null) {
        String filePath = null;
        Uri uri = data.getData();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
          filePath = BitmapUtils.getPath(uri);
        } else {
          String[] cloums = {MediaStore.Images.Media.DATA};
          cursor = getContentResolver().query(uri, cloums, null, null, null);
          cursor.moveToFirst();
          filePath = cursor.getString(0);
        }
        BitmapUtils.cropImageUri(filePath);
      }
    } finally {

      if (cursor != null) cursor.close();
      System.gc();
    }
    if (requestCode == GloableUtils.CROP_A_PICTURE) {
      Bitmap bitmap = null;
      try {
        String path = "/mnt/sdcard/temp.jpg";
        bitmap = BitmapUtils.compressPictureFromFile(path);
        String pictureBytes = ParseUtils.getBase64FromBitmap(bitmap);
        pictureBytes = "data:image/png;base64," + pictureBytes;
        webView.loadUrl("javascript:G_jsCallBack.selectHeadPic_callback('" + pictureBytes + "')");
      } catch (Exception e) {
        ExUtil.e(e);
      } finally {
        BitmapUtils.recyleBitmap(bitmap);
      }
    }
    if (requestCode == GloableUtils.CHOOSE_PICTURE_ONLY && data != null) {
      Bitmap bitmap = null;
      try {
        Uri uri = data.getData();
        String storagePath = BitmapUtils.getPath(uri);

        getImageBase(storagePath);
        //                     base = "data:image/png;base64," + base;
        //                     Log.i("if", "打印bsdfs" + base);
        // 选择无裁剪图片成功后上传base64字符串
        // TODO
        //                     webView.loadUrl("javascript:G_jsCallBack.selectPic_callback('" + base
        // + "')");

      } finally {
        BitmapUtils.recyleBitmap(bitmap);
      }
    }

    if (requestCode == GloableUtils.FILECHOOSER_RESULTCODE) {
      if (null == myUploadMsg) return;
      Uri result = data == null || resultCode != RESULT_OK ? null : data.getData();
      myUploadMsg.onReceiveValue(result);
      myUploadMsg = null;
    }
  }