HTML Canvas Image random pixel
<!DOCTYPE html> <html> <head> <title>Manipulating images and video</title> <meta charset="utf-8"> // w ww.j a va2 s . c o m <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var canvas = $("#myCanvas"); var context = canvas.get(0).getContext("2d"); // Randomising pixels var imageData = context.createImageData(200, 200); var pixels = imageData.data; var numPixels = imageData.width*imageData.height; // Access and change pixel values for (var i = 0; i < numPixels; i++) { pixels[i*4] = Math.floor(Math.random()*255); // Red pixels[i*4+1] = Math.floor(Math.random()*255); // Green pixels[i*4+2] = Math.floor(Math.random()*255); // Blue pixels[i*4+3] = 255; // Alpha }; // Draw image data to the canvas context.putImageData(imageData, 0, 0); }); </script> </head> <body> <canvas id="myCanvas" width="500" height="500"> <!-- Insert fallback content here --> </canvas> </body> </html>