编辑图像后如何更新android画廊的缩略图预览 [英] how to update thumbnails preview of android gallery after image edited

查看:231
本文介绍了编辑图像后如何更新android画廊的缩略图预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复

使用MediaScanner刷新缩略图

我对内置画廊中的android中的缩略图更新有问题.实际上,我已经打开,编辑并保存了在图库中选择的图像.

I have a problem regarding the update of thumbnails in the android in built-in gallery. Actually I have opened, edited and saved the image which was selected in the gallery.

我打开离开图库,然后再次打开图库,然后该图像的缩略图不会更新.但是,我选择了图像,它确实是经过编辑的版本.

I open leave the gallery and open the gallery again, then the thumbnail for that image is not updated. However, I pick the image, it is the edited version indeed.

有人对此有解决方案吗?我已经搜索过,但是我得到了有关使用sendBroadcast()刷新图库的答案,该似乎没有更新图像预览.

Does anybody have solution about this? I have search but I'm getting the answer about refreshing the gallery using sendBroadcast(), which does not seem to update the image previews.

编辑

我不想删除现有文件,因为假设用户要使用其他名称保存文件,则该文件不受影响

I don't want to delete the existing file because suppose user want to save file with different name then that file did not affected

推荐答案

我找到了解决此问题的方法,在请求新缩略图之前,您需要删除旧缩略图.为此使用MediaStore和ContentResolver

I found a workaround for this problem, before you request a new thumbnail you need to delete old one. Use MediaStore and ContentResolver for this

private static void removeThumbnails(ContentResolver contentResolver, long photoId) {
Cursor thumbnails = contentResolver.query(Thumbnails.EXTERNAL_CONTENT_URI, null, Thumbnails.IMAGE_ID + "=?", new String[]{String.valueOf(photoId)}, null);
for (thumbnails.moveToFirst(); !thumbnails.isAfterLast(); thumbnails.moveToNext()) {

    long thumbnailId = thumbnails.getLong(thumbnails.getColumnIndex(Thumbnails._ID));
    String path = thumbnails.getString(thumbnails.getColumnIndex(Thumbnails.DATA));
    File file = new File(path);
    if (file.delete()) {

        contentResolver.delete(Thumbnails.EXTERNAL_CONTENT_URI, Thumbnails._ID + "=?", new String[]{String.valueOf(thumbnailId)});

    }

}

您可以从其URI中获取photoId,从文件名中获取URI,只需创建File并从中解析URI

You can get photoId from its URI, to get URI from file name just create File and parse URI from it

Uri uri = Uri.fromFile(file);

这篇关于编辑图像后如何更新android画廊的缩略图预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆