简体   繁体   中英

Open specific image from album

I'm making a simple Android app and from my app I want to take an image and save it in the album. After the image is taken I take the 'requestCode' in a database (saveImageId).

public void makePicture(){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_ID);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_ID) {
        Bitmap thumbnail = (Bitmap)data.getExtras().get("data"); 
        Log.d("picture receive","foto ok?");
        saveImageId = requestCode;
        _ivPicture.setImageBitmap(thumbnail);
    }
}

When I want to show the image I read the code out of the database. I have to search the image with the requestCode and show it to the user.

Anyone got any idea how I can show the image in the _ivPicture? Regards

Found it, had to save the place of the picture:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_ID) {
        Log.d("picture receive","foto ok?"+requestCode+" & "+resultCode);
        Uri pictureTaken = data.getData();
        Bitmap thumbnail = (Bitmap)data.getExtras().get("data"); 
        saveImageId = pictureTaken.toString();
        Log.d("saveImageId=",""+saveImageId);
        _ivPicture.setImageBitmap(thumbnail);
    }
}

the saveImageId is going to the database (as a string), afterwards I had to load the image again with : Uri myUri = Uri.parse(saveImageId); _ivPicture.setImageURI(myUri); Uri myUri = Uri.parse(saveImageId); _ivPicture.setImageURI(myUri);

I think you need to correct the main part of your code above.

if (requestCode == CAMERA_PIC_ID) {
    Uri uri = data.getData(); 
    Bitmap thumbnail = Media.getBitmap(getContentResolver(), uri);
    _ivPicture.setImageBitmap(thumbnail);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM