在 Android 中显示来自休息服务器的 gif/动画图像视图
在我的应用程序中,我想在一些特殊事件(如万圣节、感恩节、圣诞节等)启动时显示一些动画。
我没有找到在视图中显示动画 .gif 的热门方法。我发现的最接近的解决方案是使用 gif 帧制作一个 AnimationDrawable。
我正在尝试实现这一点,但对如何存储(目前我正在使用 LAMP 服务器)、传输和恢复服务器所需的资源到 Android 设备有一些疑问。
将 .gif 数据下载到手机并以编程方式提取帧和帧速率是一个很好的解决方案,否则会给客户端增加不必要的负载?如果适用,是否有一些库或源可以指导我完成该任务?
如果我想在服务器中处理 gif,然后将其逐帧提供给客户端,我该怎么做?我想过用图像的 URL 制作 JSON 并下载它们,但这可能不是一个好的选择,因为我需要大量的 http 连接,并且如果网络延迟很高,加载可能会更慢
Where我能找到gif的内部结构吗?我在 Google 中搜索过,但没有找到任何结果
提前致谢
In my application I'd like to show some animations at the startup in some special events like Halloween, Thanksgiving, Christmas etc.
I didn't find a hot to show an animated .gif in a View. The closest solution I found is to make an AnimationDrawable with the gif frames.
I'm trying to implement that but have some questions about how to store (currently i'm using a LAMP server), transfer and recover the resources needed from the server to the Android device.
Downloading the .gif data to the phone and extract there the frames and framerate programmatically is a nice solution or it will add an unnecessary load to the client? If its appropriated is there some library or source for guiding me in with that task?
If I want to handle the gif in the server and then I want to serve it to the client frame-by-frame, how can I do that? I've thought in making a JSON with the URL's of the images and download them but maybe is not a nice option since I'd need a lot of http connections and the load could be slower if the network latency is high
Where can I find the internal structure of a gif? I have searched in Google but nothing found
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想提取 gif 文件来获取帧和帧速率,你需要一个 GIF 解码器,然后将它们应用到
AnimationDrawable
此将帮助您以图表方式添加帧。这两个链接可以帮助您在androidhttp://www.basic4ppc中提取gif图像
。 com/android/help/gifdecoder.html
http://code.google.com/p/loon-simple/source/browse/trunk/android/LGame-Android-0.2.6S/org/loon/framework/android/game/core/ GIFDecoder.java?r=7
if you want to extract the gif file to get the frames and the frame rate you need a GIF decoder and then applay them to the
AnimationDrawable
this will help you to add frames diagrammatically.this two links can help you to extract the gif image in android
http://www.basic4ppc.com/android/help/gifdecoder.html
http://code.google.com/p/loon-simple/source/browse/trunk/android/LGame-Android-0.2.6S/org/loon/framework/android/game/core/GIFDecoder.java?r=7
一定要在客户端进行。您看过这个吗?将动画分割成多个图像并使用 AnimationDrawable 在客户端渲染它可能是唯一的方法。
Definitely do it on the client side. Have you seen this? Splitting the animation into multiple images and rendering it on the client side with an AnimationDrawable may be the only way to go.
您需要扩展视图才能播放 .gif
考虑以下代码
在 xml 中使用此视图并提供 url,
如果存在网络延迟,请在单独的线程中下载 gif 并将输入流提供给构造函数
将其更改为
You will require to extend a view to make it to play .gif
Consider the following code
Use This view in you xml and supply the url,
If network Latency is present download the gif in separate thread and supply the input stream to the constructor
Change it to