0

I have four image views in my screen and capture images from camera and displayed in it, now i want to upload those images into the server. So i have used the below code to get the path of those but it's through the exception. Is there any possible to upload the images into the server from image view which is capture from camera(without store the images into the memory).

         if (requestCode == 1&& resultCode == RESULT_OK)
                {
                    Bitmap photo = (Bitmap) data.getExtras().get("data");
                    purchase_Img_1.setImageBitmap(photo);
                    Uri tempUri = getImageUri(getApplicationContext(), photo);
                    File finalFile = new File(getRealPathFromURI(tempUri));

                }

    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);
        return Uri.parse(path);
    }

public String getRealPathFromURI(Uri uri) {
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Vengat
  • 235
  • 1
  • 5
  • 16
  • 1
    Possible duplicate of [Getting path of captured image in android using camera intent](https://stackoverflow.com/questions/20327213/getting-path-of-captured-image-in-android-using-camera-intent) – Goku Nov 20 '17 at 12:04
  • which exception throw ? – Vij Nov 20 '17 at 12:04

2 Answers2

1
Getting path of captured image from imageviews 

There is no path. There are no paths. You got bitmaps and placed those in views.

Uri tempUri = getImageUri(getApplicationContext(), photo);

Here you stored a bitmap using MediaStore. You got back an uri.

You can open an inputstream for that uri, read from it and upload the bytes.

But with using the MediaStore you saved the bitmap to file. If you do not want that you better compress the bitmap to a ByteArrayOutputStream and upload the resulting byte array.

greenapps
  • 11,154
  • 2
  • 16
  • 19
0

Get rid of most of that code. Save the Bitmap to a file using compress(). Now you know where the file is and can use that for your server upload process.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491