简体   繁体   English

刷新图库中的图像缩略图

[英]Image Thumbnail Refresh in Gallery

For my application, I need to refresh thumbnail image of gallery. 对于我的应用程序,我需要刷新图库的缩略图。

Because whenever I update my image content that thing don't reflected on thumbnail. 因为每当我更新图像内容时,该内容都不会反映在缩略图上。 The thumbnail image show first time image creation data not the present one. 缩略图图像显示的是第一次图像创建数据,而不是当前图像。

But actual image contain new data so I need to reflect it into thumbnail also. 但是实际图像包含新数据,因此我也需要将其反映到缩略图中。 After wandering this forum I found following code snipper to delete current thumbnail but I can't able to call this function because I don't able to get photoId. 在这个论坛上徘徊后,我发现以下代码片段删除器删除了当前缩略图,但由于无法获取photoId,因此无法调用此函数。

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

At present I was calling this function as 目前,我将此功能称为

removeThumbnails(pexelMimics.getContentResolver(),
            ContentUris.parseId(uri));

I think this trick will work for me. 我认为这个技巧对我有用。 But this is my guess. 但这是我的猜测。 If you guys have better solution for this problem then please help me. 如果你们对这个问题有更好的解决方案,请帮助我。

At the time of image saving, I have to provide following code to delete image content. 保存图像时,我必须提供以下代码来删除图像内容。

activity.getContentResolver().delete(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            MediaColumns.DATA
                    + "='"
                    + GameManager.getInstance().getSavedImageFilePath()
                            .replaceAll("'", "''") + "'", null);

After this I got new content in thumbnail icon. 之后,我在缩略图图标中获得了新内容。

You don't mention what class and inheritance you have; 您没有提及您拥有的类和继承; if you are in a class the inherits BaseAdapter, then you can do 如果您在继承BaseAdapter的类中,则可以

notifyDataSetChanged();

after you change the thumbs. 改变拇指之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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