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 to Object / 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 the ImageData
object is a CanvasPixelArray
, 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 call ctx.createImageData(width,height)
.
Then you can get its data
array and you are sure its type will be correct.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.