从相册中打开特定图像

时间:2011-04-06 10:39:17

标签: android image bitmap camera

我正在制作一个简单的Android应用程序,并且从我的应用程序中我想拍摄图像并将其保存在相册中。拍摄图像后,我在数据库中使用'requestCode'(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);
    }
}

当我想要显示图像时,我从数据库中读取代码。我必须使用requestCode搜索图像并将其显示给用户。

任何人都知道如何在_ivPicture中显示图像? 此致

2 个答案:

答案 0 :(得分:1)

发现它, 不得不保存图片的位置:

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

saveImageId将转到数据库(作为字符串),之后我不得不再次加载图像:Uri myUri = Uri.parse(saveImageId); _ivPicture.setImageURI(myUri);

答案 1 :(得分:0)

我认为你需要纠正上面代码的主要部分。

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