从相机返回缩略图文件路径

时间:2015-01-27 22:33:49

标签: android cordova

所以我分叉cordova camera plugin因为我想修改它以在拍摄照片时返回缩略图和常规尺寸的图像。我之前从未做过Android开发,但这是我到目前为止所做的:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;
    // if camera crop
if (requestCode == CROP_CAMERA) {
  if (resultCode == Activity.RESULT_OK) {
    Bitmap thumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(croppedUri.toString()), 100, 100);
    Uri thumbNailUri = getImageUri(this.cordova.getActivity().getApplicationContext(), thumbImage);
    JSONArray imageArray = new JSONArray();
    imageArray.put(croppedUri.toString());
    imageArray.put(thumbNailUri.toString());
    this.callbackContext
        .success(imageArray);
    croppedUri = null;

  }// If cancelled
  else if (resultCode == Activity.RESULT_CANCELED) {
    this.failPicture("Camera cancelled.");
  }

  // If something else
  else {
    this.failPicture("Did not complete!");
  }

}

public Uri getImageUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = android.provider.MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
      return Uri.parse(path);
    } 

问题是执行此代码时应用程序崩溃了。似乎调用BitmapFactory.decodeFile(croppedUri.toString())返回一个空值。

我在上面链接的回购邮件中使用的所有代码都是here。我试图做的就是将图像路径返回到常规尺寸图像和缩略图。

0 个答案:

没有答案