Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to get path of captured image in android

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
        knop.setVisibility(Button.VISIBLE);


        // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
        Uri tempUri = getImageUri(getApplicationContext(), photo);

        // CALL THIS METHOD TO GET THE ACTUAL PATH
        File finalFile = new File(getRealPathFromURI(tempUri));

        System.out.println(mImageCaptureUri);
    }  
}

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

public String getRealPathFromURI(Uri uri) {
    String path = "";
    if (getContentResolver() != null) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
            path = cursor.getString(idx);
            cursor.close();
        }
    }
    return path;
}
Comment

PREVIOUS NEXT
Code Example
Java :: android studio start activity 
Java :: java http request post 
Java :: append button jframe 
Java :: bat artifact 
Java :: how to get contacts permission in android 
Java :: how to get length of integer in java 
Java :: how to set the backtound color in java 
Java :: play sound on button click android studio 
Java :: list in java 
Java :: int to binary java 
Java :: java code examples 
Java :: Java @Inherited 
Java :: java days between 
Java :: java discord bot get id of message it just sent 
Java :: how to change maven java version in po, 
Java :: how to change color page in latex 
Java :: date java format 
Java :: Triangle Pattern In Java 
Java :: jagged array java 
Java :: java foreach list 
Java :: offsetdattime to date 
Java :: java parallel sort 
Java :: Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: how to create an array list of ints in java 
Java :: java rps 
Java :: java sort list of strings 
Java :: open file java 
Java :: return empty array from method 
Java :: len of number in java 
Java :: concatenate two arrays java 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =