Android Gallery(查看)视频(还有缩略图问题)
目前我们有一个图库视图,我们需要向其中添加图像/视频的缩略图。如果我们已经有了图像/视频的 content:// URI,我们如何获取已经生成的缩略图(本机图库应用程序显示的缩略图)?
(我们使用的是Android 1.6,Video.Thumbnails不存在)
Currently we have a Gallery view to which we need to add thumbnails for images/video. How do we get the already generated thumbnails (the ones that the native Gallery app shows) if we already have the image's/video's content:// URI?
(We are using Android 1.6, Video.Thumbnails does not exist)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
给你......工作得很好......!
http://mihaifonoage.blogspot.com/ 2009/09/displaying-images-from-sd-card-in.html
Here you go.. working very nicely....!
http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html
如果我理解正确的话,您可以通过内容提供商提供图像和视频,并可以通过 URI 进行访问。您想要为此类图像和视频创建缩略图。
我不知道如何对视频文件执行此操作,但这就是我用图像文件实现它的方法。
使用ContentResolver的openInputStream方法将图像作为InputStream打开。 http://developer.android. com/reference/android/content/ContentResolver.html#openInputStream%28android.net.Uri%29
使用此方法使用上述InputStream创建一个BitmapDrawable
http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#BitmapDrawable%28android.content.res.Resources,%20java.io.InputStream%29
将 BitmapDrawable 缩小到所需的缩略图宽度和高度。按照本教程进行操作。
http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
[可选]您可能想要缓存缩略图,以便每次用户访问您的图库时都不必重复上述步骤。
If I understand correctly, you have images and videos served by content provider and accessible as URIs. You want to create thumbnails for such images and videos.
I don't know how to do this with video files, but this is how I will implement it with image files.
Open the image as InputStream using ContentResolver's openInputStream method. http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream%28android.net.Uri%29
Create a BitmapDrawable with the above InputStream using this method
http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#BitmapDrawable%28android.content.res.Resources,%20java.io.InputStream%29
Scale down the BitmapDrawable to desired width and height of thumbnail. Follow this tutorial.
http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
[Optional] You may want to cache the thumbnail, so that you don't have to repeat above steps everytime the user accesses your Gallery.
我认为对于图像,上面的答案可能有用。对于视频,原生 Gallery 应用程序使用 MediaMetadataRetriever 类,但不幸的是,这不是已发布的 API。
I think for Images, the answers above could be useful. For videos, the class MediaMetadataRetriever is what is used by the native Gallery app., but unfortunately, that is not a published API.