gpt4 book ai didi

javascript - MobileSafari 未通过 JavaScript 返回正确的图像大小信息

转载 作者:数据小太阳 更新时间:2023-10-29 05:23:34 24 4
gpt4 key购买 nike

我有一个 HTML test page for this issue here .出于某种原因,MobileSafari 将任何超过 1700 像素的图像的 Image.width/height 属性报告为其值的一半。也就是说,JPG 的 width 属性是 2000,但 MobileSafari JavaScript 将其报告为 1000。如果我对 1700 像素宽的图像尝试相同的代码,我会得到正确的宽度。

The test我确实加载了两个图像(不同尺寸的相同图像)并显示了 JavaScript 大小值。我试过:

  • Mac OS X 10.6.8 中的 Chrome 22、Safari 5.1.7、Firefox 15.0.1(正确大小)
  • iOS 模拟器 4.3 SDK 3.2(大小不正确)
  • 装有 iOS 5.1 的 iPad 2(尺寸不正确)
  • 装有 iOS 5.1 的 iPhone 4S(尺寸不正确)

知道为什么会这样吗?我在某处缺少设置吗?为什么它适用于某些图像而不适用于其他图像?

测试在这里:http://still-island-1941.herokuapp.com/sizetest.html

这是 JavaScript 代码:

    var imgBig, imgSmall;

function init() {
imgBig = new Image();
imgBig.onload = handleBig;
imgBig.src = "/images/size.jpg";
imgSmall = new Image();
imgSmall.onload = handleSmall;
imgSmall.src = "/images/test1.jpg";
document.getElementById("browser").innerHTML = navigator.userAgent;
}

function handleBig() {
document.getElementById("dimensionsBig").innerHTML = imgBig.width + "x" + imgBig.height;
document.getElementById("testBig").src = imgBig.src;
}

function handleSmall() {
document.getElementById("dimensionsSmall").innerHTML = imgSmall.width + "x" + imgSmall.height;
document.getElementById("testSmall").src = imgSmall.src;
}

这是 HTML 代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<title>MobileSafari image dimensions test</title>
</head>
<body onload="init()">
<p>your browser: <strong><span id="browser"></span></strong></p>
<p>big image dimensions: <strong><span id="dimensionsSmall"></span></strong> (should be 1700x1134)</p>
<img id="testSmall" />
<p>small image dimensions: <strong><span id="dimensionsBig"></span></strong> (should be 2000x1334)</p>
<img id="testBig" />
</body>
</html>

最佳答案

是的,它存在尺寸和重量的限制。

由于 iOS 上的可用内存,它可以处理的资源数量受到限制:

对于小于 256 MB RAM 的设备,解码 GIF、PNG 和 TIFF 图像的最大尺寸为 3 兆像素,对于大于或等于 256 MB RAM 的设备,最大尺寸为 5 兆像素。也就是说,对于内存小于 256 MB 的设备,确保 width * height ≤ 3 * 1024 * 1024。请注意,图像的解码尺寸远大于编码尺寸:

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.

一些可能有帮助的链接:

干杯

关于javascript - MobileSafari 未通过 JavaScript 返回正确的图像大小信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12556198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com