从相册中打开特定图像

发布于 2024-10-30 17:19:47 字数 711 浏览 1 评论 0原文

我正在制作一个简单的 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 中显示图像吗? 问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我老 2024-11-06 17:19:47

找到了,
必须保存图片的位置:

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

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

人生戏 2024-11-06 17:19:47

我认为您需要更正上面代码的主要部分。

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文