在 iOS 模拟器版本 4.3.2 中的 mobile safari 中显示蓝色问号(应该是 GIF 图像)
本地存储在服务器上的 GIF 图像(86.8KB、1430x2246)无法显示在运行 iOS 4.2.1 的 iPhone 3G 设备上的移动网站上。该网站是使用 jQuery Mobile 和 HTML5 构建的。
以下是我测试的设备和平台以及加载图像的结果:
- 所有主要桌面浏览器(即Win/IE、Mac/Win Safari、Mac/Win Chrome、Win/Opera、Mac/Win FireFox)。通过
- iPhone 3G,运行 iOS 4.2.1,Mobile Safari。 失败
- Opera Mini,在上述 iPhone 3G 设备上。通过了
- 一位同事的 iPhone 4S,运行 Mobile Safari。通过
- iOS 模拟器,硬件 -> 版本 5.0,移动 Safari。通过
- iOS 模拟器,硬件 -> 版本 4.3.2,移动 Safari。 失败
- Android 设备,版本 2.3.3。通过
- Android SDK 模拟器,版本 1.5、2.2、2.3.3。通过
我决定将注意力集中在 iOS 模拟器版本 4.3.2 上,因为该图像甚至无法在功能强大的台式计算机上加载。
我认为这可能是 iOS 4.3.2 和 Mobile Safari 的内存问题,可能与图像的资源限制有关(iOS 开发指南)。我知道有一个解决图像限制(即 6.5MB)的方法,但这对我来说也不起作用(稍后记录)。
我接下来看的是图像的大小和尺寸。我从互联网上下载了一些免费图像(另存为 GIF)并将它们本地存储在服务器上,除了一张之外,所有图像的大小和尺寸都与相关图像相似或更大,并且它们都在 iOS 模拟器版本 4.3.2 中成功加载。
仅供参考,图像大小和尺寸为:
- 238KB、2428x1531
- 414KB、2993x2050
- 238KB、2000x1490
- 196KB、2192x2541
- 196KB、850x638
回到图像解决方法,如果我理解正确的话,主要思想是将 img 包装在 canvas 标签中(我在 JavaScript 中正确调用了 drawImage 函数),我做到了。不幸的是,GIF 仍然没有加载。我也尝试将图像作为背景图像加载到 div 标签中,但同样,这不起作用。
我想不出还有什么可以尝试的。 GIF 是否可能已损坏?老实说,我不知道我还能做什么。
让我添加上面我尝试过但失败的所有方法,我下载的其他图像都工作正常(同样,在 iOS 模拟器版本 4.3.2 的上下文中)。我什至查看了一些简单的错误,例如拼写错误,以及相关 GIF 的来源和文件名拼写是否正确。我什至尝试将图像扩展名从 GIF 更改为 JPG,然后更改为 PNG,但图像仍然无法加载。
我将不胜感激任何帮助。谢谢。
更新
我尝试使用此处的链接检查图像的有效性,如何以编程方式检查图像(PNG、JPEG 或 GIF)是否已损坏?,并且图像未损坏。如果我找到解决方案,我一定会记录下来。
谢谢。
Update2
我获得了 iranView 的副本,并将 GIF 保存为 JPG(不只是重命名,这是我上次所做的),并将图像加载到 iOS Simulator,版本 4.3.2,Mobile Safari 中。使用同样的方法,我尝试将 GIF 保存为 PNG,因为 JPG 太大,但它没有加载。然后,我尝试将 GIF 保存为 JPG,又将 JPG 保存为 GIF,但它也没有加载。只有 JPG 有效。
Update3
事实证明,我测试的这些图像确实是 JPEG;所以,我不得不重新测试。我从 Google 图片下载了图片,确保它们是 GIF 并且大于 2 MP。这是我发现的:
重新阅读 Apple 开发者网站上的已知 iOS 资源限制部分,它说:
解码的 GIF、PNG 和 TIFF 图像的最大尺寸为 3 兆像素 适用于 RAM 小于 256 MB 且小于 5 兆像素的设备 具有大于或等于 256 MB RAM。即保证宽度* 对于 RAM 小于 256 MB 的设备,高度 ≤ 3 * 1024 * 1024。笔记 解码后的大小远远大于图像的编码大小。
JPEG 的最大解码图像大小为 32 兆像素,使用 二次抽样。 JPEG 图像可达 32 兆像素,因为 子采样,允许 JPEG 图像解码为具有 1 的大小 第十六为像素数。大于 2 兆像素的 JPEG 图像 被二次采样,即解码为减小的尺寸。 JPEG二次采样 允许用户查看来自最新数码相机的图像。
对于具有以下功能的设备,画布元素的最大尺寸为 3 兆像素 小于 256 MB RAM 和 5 兆像素的设备 等于 256 MB RAM。画布对象的高度和宽度为 150 x 300 像素(如果未指定)。
如果以上都是铁定的,那么为什么图像“earth_lights.gif”和“logoJDC_orange_GIF.gif”在iPhone 3G(4.2.1)上显示,但在iOS模拟器(4.3.2)上不显示?我使用 IrfanView 测试了所有图像,以确保它们的格式正确 - GIF 是真正的 GIF,JPG 是真正的 JPG。基于所有这些测试,我倾向于推断 Mobile Safari 对 GIF 的解码(至少在过时的 iOS 固件上)是不一致的,而不是得出我最初尝试显示的 GIF 图像已损坏的结论。
A GIF image, stored locally on the server (86.8KB, 1430x2246), is not displaying on a mobile website on my iPhone 3G device, running iOS 4.2.1. The site is built with jQuery Mobile and HTML5.
Here are devices and platforms I tested and the result of loading the image:
- All major desktop browsers (i.e. Win/IE, Mac/Win Safari, Mac/Win Chrome, Win/Opera, Mac/Win FireFox). PASSED
- iPhone 3G, running iOS 4.2.1, Mobile Safari. FAILED
- Opera Mini, on said iPhone 3G device. PASSED
- A colleague's iPhone 4S, running Mobile Safari. PASSED
- iOS Simulator, with Hardware->Version 5.0, Mobile Safari. PASSED
- iOS Simulator, with Hardware->Version 4.3.2, Mobile Safari. FAILED
- Android device, Version 2.3.3. PASSED
- Android SDK Emulator, Versions 1.5, 2.2, 2.3.3. PASSED
I decided to focus my attention on the iOS Simulator, Ver 4.3.2, since the image didn't even load up on a powerful desktop computer.
I thought it may be a memory issue with iOS 4.3.2 and Mobile Safari, perhaps related to the resource limits for images (iOS Development Guidelines). I understand there is a workaround for image limits (i.e. 6.5MB) but that didn't work for me, either (documented later).
The next thing I looked at was the size and dimension of the image. I downloaded a few free images (saved as GIFs) from the Internet and stored them locally on the server, all but one similar or larger in size and dimension than the image in question and they all loaded successfully in iOS Simulator, Ver 4.3.2.
FYI, the image sizes and dimensions were:
- 238KB, 2428x1531
- 414KB, 2993x2050
- 238KB, 2000x1490
- 196KB, 2192x2541
- 196KB, 850x638
Going back to the image workaround, if I understand it right, the main idea is wrap the img in a canvas tag (I correctly called the drawImage function in JavaScript), which I did. Unfortunately, the GIF still did not load. I tried loading the image as a background-image in a div tag, as well, and, again, this did not work.
I can't think of anything else to try. Is it possible the GIF is corrupt? I honestly have no idea what else can I do.
Let me add in all the above methods I tried that failed, the other images I had downloaded all worked correctly (again, within the context of iOS Simulator, Version 4.3.2). And I even looked at the simple mistakes like spelling errors and the source and filename of the GIF in question is spelled correctly. I even tried changing the image extension from GIF to JPG and then PNG and the image still did not load.
I would appreciate any help. Thank you.
Update
I tried checking the validity of the image using the link here, How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?, and the image was not corrupt. If I find a solution, I'll be sure to document it.
Thank you.
Update2
I got a copy of iranView and saved the GIF as a JPG (not just renamed it, which is what I did last time) and the image loaded in iOS Simulator, version 4.3.2, Mobile Safari. Using this same method, I tried saving the GIF as a PNG, because JPG is too large, but it did not load. Then, I tried saving the GIF as a JPG, and I saved the JPG as a GIF, but it did not load, either. Only JPG worked.
Update3
It turns out that those images I tested are really JPEGs; so, I had to retest. I downloaded the images from Google images, ensuring they are GIFs and larger than 2 MP. Here is what I found:
Re-reading the Known iOS Resource Limits section from the Apple Developer site, it says:
The maximum size for decoded GIF, PNG, and TIFF images is 3 megapixels
for devices with less than 256 MB RAM and 5 megapixels for devices
with greater or equal than 256 MB RAM. That is, ensure that width *
height ≤ 3 * 1024 * 1024 for devices with less than 256 MB RAM. Note
that the decoded size is far larger than the encoded size of an image.The maximum decoded image size for JPEG is 32 megapixels using
subsampling. JPEG images can be up to 32 megapixels due to
subsampling, which allows JPEG images to decode to a size that has one
sixteenth the number of pixels. JPEG images larger than 2 megapixels
are subsampled—that is, decoded to a reduced size. JPEG subsampling
allows the user to view images from the latest digital cameras.The maximum size for a canvas element is 3 megapixels for devices with
less than 256 MB RAM and 5 megapixels for devices with greater or
equal than 256 MB RAM. The height and width of a canvas object is 150
x 300 pixels if not specified.
If all the above is ironclad, then why does images "earth_lights.gif" and "logoJDC_orange_GIF.gif" display on the iPhone 3G (4.2.1), yet does not display on iOS Simulator (4.3.2)? I tested all images with IrfanView to ensure their formats are correct - GIFs are truly GIFs and JPGs are truly JPGs. Based on all this testing, I'm leaning towards deducing Mobile Safari's decoding of GIFs, at least on dated iOS firmware, is inconsistent, as opposed to concluding the GIF image I was originally trying to display is corrupt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论