title: HTML5 Canvas toDataURL("image/png") works on some paintings and some not, not sure why
body: <p>I'm using asp.net 4 (c#).
  I have a drawing app on an Html 5 canvas, with ability to add images and to draw with many colors.
  I would like to save the image drawen to .png file.
  In order to do that, I've built a WebMethod:</p>
  
  <pre><code>[WebMethod(EnableSession = true)]
  public static void UploadImage(string imageData,string name)
  {
      System.Diagnostics.Debug.WriteLine("here friend!");
  }
  </code></pre>
  
  <p>Now I have a button on the page, and I use javaScript to call this method:</p>
  
  <pre><code>function trySend()
  {
      var image = document.getElementById("drawCanvas").toDataURL("image/png");
      image = image.replace('data:image/png;base64,', '');
      var name = document.getElementById("userName").value;
      $.ajax(
      {
          type: 'POST',
          url: 'CanvasSave.aspx/UploadImage',
          data: '{ "imageData" : "' + image + '" ' + ', "name" : "' + name + '"}',
          contentType: 'application/json; charset=utf-8',
          dataType: 'json',
          success: function (msg) {
          location.href = '&lt;%= Page.ResolveUrl("~/ShowCards.aspx") %&gt;';
          }
       });
  }
  </code></pre>
  
  <p>The thing is, that if I draw a simple drawing on the canvas (some lines or a small circle) it works perfectley.
  Even If I had 1 of the "stamps" (which are images), it still works.</p>
  
  <p>If I draw a "complicated" image (not really complicated! just a scratch with different colors) or add 2,3 stamps it dosen't work. The WebMethod is not called at all , even If I wait for a long while.</p>
  
  <p>I think that it has to do something with the size of the image. It seems that if the final size of the data less the 80 kb (this is the max size of the image I was able to save) then it works, but if the intended image will be larger than this I have a problem.
  Again, the all problem is in the JS not in the C# code.</p>
  
  <p>THis is the JavaScript Error i get:</p>
  
  <pre><code>    POST http://localhost:53751/CanvasSave.aspx/UploadImage 500 (Internal Server Error) 
  jquery.min.js:4
  f.support.ajax.f.ajaxTransport.send jquery.min.js:4
  f.extend.ajax jquery.min.js:4
  trySend Default.aspx:21
  onclick
  </code></pre>
  
  <p>What is the reason for this problem and how can I fix it?</p>