【问题标题】:How can I capture image and after crop the captured image and replace it with crop image?如何捕获图像并在裁剪捕获的图像并将其替换为裁剪图像后?
【发布时间】:2014-05-14 16:35:36
【问题描述】:

这似乎是重复的,但不是请看我的问题。

我在 google 和 stackoverflow 上搜索过很多次。 我找到了很多例子,但没有一个不能解决我的问题。

我需要的是:

我想捕获图像并保存它(我给出路径)然后我想裁剪它并将它保存在同一个地方(我的意思是用裁剪的图像替换原始文件)

我所做的是:

我用这个来拍照:

 Intent cameraIntent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE); 
 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); // outputFileUri is my path
 startActivityForResult(cameraIntent, TAKE_PHOTO_CODE); 

为了裁剪图像,我在 stackoverflow 上使用了这个示例:

this

做了什么:

我捕获图像并在捕获后运行裁剪图像方法,它也很好。

完成裁剪后,我看不到裁剪后的图像,它只是捕获的图像。

有什么问题:

没有错误,但我想看到捕获的图像将替换为原始捕获的图像。

提前致谢!!

【问题讨论】:

  • code.tutsplus.com/tutorials/… 看到这个链接
  • 感谢您的回答,我在我的项目中实现了这个,在我捕获图像后有两个选项,裁剪照片和裁剪图片,裁剪照片对我来说很好,但裁剪图片在我的手机上不起作用,我该如何解决这个问题?

标签: android android-camera android-capture


【解决方案1】:

试试这个,onActivityResult你会返回数据

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {


    case Utils.CROP_IMAGE:
        if (resultCode == RESULT_OK) {
            // Create an instance of bundle and get the returned data
            try {
                Uri outputFileUri = data.getData();
                             String path = getRealPathFromURI(outputFileUri)

            } catch (Exception e) {
                // TODO: handle exception
            }
        }
        break;

    default:
        break;
    }
}

获取文件路径 fome URI。

 public String getRealPathFromURI(Uri contentUri) 
 {
 String[] proj = { MediaStore.Audio.Media.DATA };
 Cursor cursor = managedQuery(contentUri, proj, null, null, null);
 int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
 cursor.moveToFirst();
 return cursor.getString(column_index);
}

【讨论】:

  • 您好,感谢您的回答,但我想要图像路径,因为我将图像发送到服务器,所以如何将裁剪图像写入捕获的图像
  • @ErsinGülbahar 我已经编辑了我的帖子,你能看到吗
  • 嗨,我可以从 getRealPathFromURI 方法中获取文件名吗?
  • 获取文件 File myFile = new File(uri.toString()); myFile.getAbsolutePath()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-15
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多