Create random-noise background image png on canvas - Javascript Canvas

Javascript examples for Canvas:image

Description

Create random-noise background image png on canvas

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
      <style id="compiled-css" type="text/css">

#adiv {/*w w  w.j av  a  2 s  .c  om*/
   width: 100px;
   height: 100px;
   background: #000;
}
#acanvas {
   display: none;
   width: 10px;
   height: 10px;
}


      </style> 
      <script type="text/javascript">
    $(function(){
var canvas = document.getElementById("acanvas");
canvas.width = 10;
canvas.height = 10;
var context = canvas.getContext("2d");
context.fillStyle = "rgba(0, 0, 255, .5)";
context.fillRect(0, 0, 5, 5);
context.fillRect(5, 5, 5, 5);
$("#adiv").css ( {
    "background": "url("+canvas.toDataURL()+")"
});
    });

      </script> 
   </head> 
   <body> 
      <div id="adiv"></div> 
      <canvas id="acanvas"></canvas>  
   </body>
</html>

Related Tutorials