check canvas empty or not

check canvas empty or not

<"canvas11" height="200px" width="200px">
 <asp:Button runat="server" ID="btn1" Text="Save" OnClientClick="checkcanvas();" />
 <script type="text/javascript">
 function checkcanvas() {
 var i = isCanvasTransparent();
 //i =true if canvas empty
 //i =false if canvas has image
 }
 function isCanvasTransparent() {
 var canvas1 = document.getElementById('canvas11');
 // true if all pixels Alpha equals to zero
 var ctx = canvas1.getContext("2d");
 var result;
 var imageData = ctx.getImageData(0, 0, canvas1.offsetWidth, canvas1.offsetHeight);
 for (var i = 0; i < imageData.data.length; i += 4)
 if (imageData.data[i + 3] !== 0) return false;
 return true;
 }
 </script>

You may also like...

Creating a Shopify App using Laravel How to Create Custom WordPress Plugin? How to Build a Telegram Bot using PHP How to Convert Magento 2 into PWA?