针对画布像素数据的跨浏览器规范? [英] Cross-browser spec for canvas pixel data?
问题描述
有没有人碰巧知道当前画布像素数据规范在各种浏览器中有多远?
当你调用或推送像素时,你得到/ send:
ImageData
data:Uint8ClampedArray
width:Number
height:Number
但我知道它以前只是:
{
data:Array
width:Number
height:Number
}
所以,如果我生成 ImageData,我如何检测我需要生成什么?是
ImageData&& Uint8ClampedArray
足够了?我会立即回到Object / Array
,还是别的什么?有没有像素阵列?
caniuse说IE10和Opera Mini不支持Uint8ClampedArray,所以...?
解决方案当调用
ctx.getImageData()
,规范要求UserAgent返回 TypedArray 。 TypedArray的支持从IE10开始。但是,与IE9一样,ImageData
对象是一个CanvasPixelArray
,没有可用的构造方法。
但无论如何,最好的和 IMK 只是跨浏览器的方式来获得正确的ArrayBuffer所需的
ImageData
Object,是调用ctx.createImageData(width,height)
。
然后你可以得到它的
数据
数组,你确定它的类型是正确的。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? Is
ImageData && Uint8ClampedArray
sufficient? And do I immediately fall back toObject / Array
, or something else? Wasn't there a pixel array at some point?[edit] caniuse says IE10 and Opera Mini don't support Uint8ClampedArray, so... ?
解决方案When calling
ctx.getImageData()
, the specs require the UserAgent to return a TypedArray without specifying which type. The support for TypedArray start with IE10. But, like in IE9, the data property of theImageData
object is aCanvasPixelArray
, which has no Constructor method available.But anyway, the best and IMK only cross-browser way to get the correct ArrayBuffer needed for
ImageData
Object, is to callctx.createImageData(width,height)
.Then you can get its
data
array and you are sure its type will be correct.这篇关于针对画布像素数据的跨浏览器规范?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!