【问题标题】:How to get RealPath of Captured image on Camera如何在相机上获取捕获图像的 RealPath
【发布时间】:2018-07-16 10:11:53
【问题描述】:

我想获取 imageview realPath 并编写 textview.. 我可以在库中获取 RealPath,但我无法在相机中获取

这是我的代码

此代码为库提供路径图像

private void takeLibrary(int sdk, String uriPath,String realPath){

    this.txtSDK.setText("Build.VERSION.SDK_INT: "+sdk);
    this.txtUriPath.setText("URI Path: "+uriPath);
    this.txtRealPath.setText(realPath);

    Uri uriFromPath = Uri.fromFile(new File(realPath));


    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uriFromPath));

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    imageView.setImageBitmap(bitmap);

}

还有这台相机

private void onCaptureImageResult(Intent data) {


   // ????????????
}

??我应该写什么请帮忙 谢谢

【问题讨论】:

  • 感谢您的回答,但我想获取 realpath imageview 我不明白您的回答
  • 检查 takePitchure() 和 onActivityResult()。我去那里了。

标签: android imageview realpath


【解决方案1】:

关注that,试试这个:

private void onCaptureImageResult(Intent data) {
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);

        File destination = new File(Environment.getExternalStorageDirectory(),
                System.currentTimeMillis() + ".jpg");

        FileOutputStream fo;
        try {
            destination.createNewFile();
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        ivImage.setImageBitmap(thumbnail);
    }

【讨论】:

【解决方案2】:
`write this piece of code in OnActivityResult()


 1. `if (requestCode == CAMERA) {
                if (data.getExtras().get("data") != null) {
                    bitmap = (Bitmap) data.getExtras().get("data");

                    uri = getImageUri(this, bitmap);

                }
            }



   2. Add this function in the class.
      public Uri getImageUri(Context inContext, Bitmap inImage) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);// this will give you the path of the image
        return Uri.parse(path);
    }

【讨论】:

  • java.lang.NullPointerException: uriString at android.app.ActivityThread.deliverResults(ActivityThread.java:4324)
猜你喜欢
  • 1970-01-01
  • 2012-02-14
  • 2013-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多