-2

I want to get imageview realPath and write textview.. I can get RealPath in library but ı cant in camera

Here is My Code

This Code Take Library İmage an Path

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);

}

And This Camera

private void onCaptureImageResult(Intent data) {


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

?? what should I write Please help Thanks

Alpaslan
  • 17
  • 1
  • 6

2 Answers2

0

Following that, try this:

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);
    }
Serge Kishiko
  • 466
  • 1
  • 6
  • 13
  • thx Serge I know this code I want get RealPath Camera image and write textview – Alpaslan Jul 16 '18 at 10:23
  • Oh, I got it! You can have a look here: [how-to-get-image-path-just-captured-from-camera](https://stackoverflow.com/questions/11591825/how-to-get-image-path-just-captured-from-camera)... Hopefully it will suit your need – Serge Kishiko Jul 16 '18 at 10:30
-1
`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);
    }
Deeksha
  • 536
  • 5
  • 14
  • Please read [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – Arash Jul 16 '18 at 10:30
  • java.lang.NullPointerException: uriString at android.app.ActivityThread.deliverResults(ActivityThread.java:4324) – Alpaslan Jul 16 '18 at 10:33