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(camer开发者_JAVA技巧aIntent, 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);
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);
}
精彩评论