Skip to content

Instantly share code, notes, and snippets.

@imaya
Created September 26, 2012 02:27
Show Gist options
  • Save imaya/3785646 to your computer and use it in GitHub Desktop.
Save imaya/3785646 to your computer and use it in GitHub Desktop.
detect android default browser putImageData bug
/**
* @return {boolean}
*/
function androidPutImageDataBug() {
/** @type {HTMLCanvasElement} */
var canvas =
/** @type {HTMLCanvasElement} */
document.createElement('canvas');
/** @type {CanvasRenderingContext2D} */
var ctx = canvas.getContext('2d');
/** @type {ImageData} */
var imageData;
/** @type {!(CanvasPixelArray|Uint8ClampedArray)} */
var pixelArray;
canvas.width = canvas.height = 1;
imageData = ctx.createImageData(1, 1);
pixelArray = imageData.data;
pixelArray[0] = pixelArray[3] = 128;
ctx.putImageData(imageData, 0, 0);
imageData = ctx.getImageData(0, 0, 1, 1);
pixelArray = imageData.data;
return (pixelArray[0] === 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment