【问题标题】:Android app crop photoAndroid 应用裁剪照片
【发布时间】:2016-11-21 03:24:41
【问题描述】:

我有一个问题。 这是我的应用程序已有的代码,它的工作方式如下:拍照 >crop > 上传。 我不想裁剪照片。我该怎么做?只是删除 dispatchCropImageIntent 方法?

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(this.getClass().getSimpleName(), "onActivityResult");
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_IMAGE_CAPTURE) {
            File imageFile = new File(mCurrentPhotoPath);
            if (imageFile.exists()) {
               dispatchCropImageIntent(Uri.fromFile(imageFile));
            }
        } else if (requestCode == REQUEST_IMAGE_FROM_GALLERY_SELECT) {
            dispatchCropImageIntent(data.getData());
        } else if (requestCode == REQUEST_PICTURE_CROP) {
            String filePath = Environment.getExternalStorageDirectory()
                    + "/temporary_holder.jpg";
            setCurrentBitmap(BitmapFactory.decodeFile(filePath));
        } else if(requestCode == CAMERA_ACTIVITY_CODE){
            // Get path
            String path = data.getStringExtra(CustomCamera.OUT_PATH);

            // Read file
            byte[] imgData = AppFS.readFileFromPath(path);
            if (imgData != null) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(imgData , 0, imgData.length);
                // TODO: Do something with the image, it should be okay
                //((ImageView)findViewById(R.id.img)).setImageBitmap(bitmap);
            } else {
                Log.e("Main", "Data is null");
            }
        }
    }
    else{
        onBackPressed();
    }
}

还有:

private void dispatchCropImageIntent(Uri uri) {
    Intent cropImageIntent = new Intent("com.android.camera.action.CROP");
    cropImageIntent.setDataAndType(uri, "image/*");
    cropImageIntent.putExtra("crop", "true");
    cropImageIntent.putExtra("noFaceDetection", true);
    cropImageIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    // retrieve data on return
    cropImageIntent.putExtra("return-data", true);
    File f = new File(Environment.getExternalStorageDirectory(),
            "/temporary_holder.jpg");
    try {
        f.createNewFile();
    } catch (IOException ex) {
        Log.e("io", ex.getMessage());
    }

    uri = Uri.fromFile(f);
    cropImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    startActivityForResult(cropImageIntent, REQUEST_PICTURE_CROP);
}

【问题讨论】:

  • 只需删除 dispatchCropImageIntent() 方法并获取该图像路径以供将来使用

标签: java android crop photo


【解决方案1】:

如果我的理解正确,您想让您的应用像这样运行:拍照 > 上传。因此,您需要将 dispatchCropImageIntent() 替换为 setCurrentBitmap()上传方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 2014-03-22
    • 2012-04-29
    相关资源
    最近更新 更多