[英]Cross-browser spec for canvas pixel data?
Does anyone happen to know how far back the current canvas pixel-data spec goes in various browsers? 有没有人碰巧知道当前画布像素数据规范在各种浏览器中有多远? And if "not that far", what the previous spec(s) were?
如果“不那么远”,以前的规格是什么?
When you call or push pixels, you get / send: 当您拨打或推送像素时,您会收到/发送:
ImageData
data: Uint8ClampedArray
width: Number
height: Number
But I know that it used to just be: 但我知道它曾经只是:
{
data: Array
width: Number
height: Number
}
So if I'm generating ImageData, how do I detect what I need to generate? 因此,如果我正在生成 ImageData,如何检测我需要生成的内容? Is
ImageData && Uint8ClampedArray
sufficient? ImageData && Uint8ClampedArray
足够? And do I immediately fall back to Object / Array
, or something else? 我会立即回到
Object / Array
或其他东西吗? Wasn't there a pixel array at some point? 在某些时候是不是有像素阵列?
[edit] caniuse says IE10 and Opera Mini don't support Uint8ClampedArray, so... ? [编辑] caniuse说IE10和Opera Mini不支持Uint8ClampedArray,所以...?
When calling ctx.getImageData()
, the specs require the UserAgent to return a TypedArray without specifying which type. 调用
ctx.getImageData()
, 规范要求UserAgent返回TypedArray而不指定哪种类型。 The support for TypedArray start with IE10. 对TypedArray 的支持从IE10开始。 But, like in IE9, the data property of the
ImageData
object is a CanvasPixelArray
, which has no Constructor method available. 但是,与在IE9中一样,
ImageData
对象的data属性是CanvasPixelArray
,它没有可用的Constructor方法。
But anyway, the best and IMK only cross-browser way to get the correct ArrayBuffer needed for ImageData
Object, is to call ctx.createImageData(width,height)
. 但无论如何,最好的和IMK只有跨浏览器的方式来获得
ImageData
Object所需的正确ArrayBuffer,就是调用ctx.createImageData(width,height)
。
Then you can get its data
array and you are sure its type will be correct. 然后你可以得到它的
data
数组,你确定它的类型是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.