如何仅在Android中列出静态图像或动画图像?
我想检测并显示最新图像,并且在用户选择上应该是动画或静态图像。 也不能取决于时间。因为
- 没有扩展
- WebP映像可能会被动画或静态(.webp)(.webp)
- ,可能是错误的程度
,可以识别图像是动画(WebP,GIF,APNG)还是静态的。 (JPG,PNG,WebP等)?
private static final String[] COLUMNS_OF_INTEREST = new String[]
{
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.WIDTH,
MediaStore.Video.Media.HEIGHT,
MediaStore.Video.Media.DATE_ADDED
};
public void printGifUri(Context context)
{
ContentResolver cr = context.getContentResolver();
String selection = MediaStore.Images.Media.MIME_TYPE + "=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("webp");
String[] selectionArgsPdf = new String[]{ mimeType };
Cursor gifCursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, COLUMNS_OF_INTEREST, selection,selectionArgsPdf,
MediaStore.Images.Media.DATE_ADDED + " DESC");
gifCursor.moveToFirst();
int columnIndexUri = gifCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
for (int i = 0; i < gifCursor.getCount(); i++)
Log.d("gif file uri -> ", gifCursor.getString(columnIndexUri));
}
我还想避免使用第三方模块,因为它们会增加应用程序的大小。您可以建议如果有任何模块可用于低尺寸。
我已经尝试检查图像文件中的Anim,VP8之类的标志的存在,并且效果很好,但是这种明确的方法很耗时。
其中的主要问题是WebP,因为相同的扩展将是静态的或动画的。这使我很难识别动画和静态类型。
I want to detect and display most recent images and it should be either animated or static images on user choice.
Also cannot depend on extentions.Because
- There would be absence of extention
- webp images could be animated or static with same extention (.webp)
- It could be wrong extentions
Is there way to identify whether images are animated (webp, gif, apng) or static (jpg, png, webp, etc)?
private static final String[] COLUMNS_OF_INTEREST = new String[]
{
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.WIDTH,
MediaStore.Video.Media.HEIGHT,
MediaStore.Video.Media.DATE_ADDED
};
public void printGifUri(Context context)
{
ContentResolver cr = context.getContentResolver();
String selection = MediaStore.Images.Media.MIME_TYPE + "=?";
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("webp");
String[] selectionArgsPdf = new String[]{ mimeType };
Cursor gifCursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, COLUMNS_OF_INTEREST, selection,selectionArgsPdf,
MediaStore.Images.Media.DATE_ADDED + " DESC");
gifCursor.moveToFirst();
int columnIndexUri = gifCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
for (int i = 0; i < gifCursor.getCount(); i++)
Log.d("gif file uri -> ", gifCursor.getString(columnIndexUri));
}
I want to also avoid the third party modules as they would increase the size of the app. You can suggest if there is any module available for this with low size.
I have Tried checking the existance of flags like ANIM, VP8, in image file and it works well but this explicit method is time consuming.
The major issue in this is webp as same extention would be static or animated. This makes difficult me to identify the animated and static type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我可能找到了一个解决方案...尝试使用
imagedecoder
文档说该文档说
因此,也许检查
imagedecoder.decodedrawable(source);
的结果是否是AnimatedImagedRawable
的实例,应帮助您确定文件是否是动画:
的 如
编辑:
对于API 28及以前,我们应该使用电影类,
我希望有助于解决您的问题
I think I maybe found a solution... try using
ImageDecoder
the documentation says
So maybe checking that the result of
ImageDecoder.decodeDrawable(source);
is an instance ofAnimatedImageDrawable
should help you figure out if a file is animated or notsuch as:
or such as
EDIT:
for API 28 and before, we should use Movie class
I hope that helps with your problem