mercredi 30 novembre 2016

Add objects and save image C# fabric.js

js]1. using asp.net mvc3. i want to draw text and rectangle on the image as group. text and rectangle can be added multiple times. after adding groups i want to save that image, Accuracy is important
I had two choices . First choice is to use canvas.toJSON(). this approach i have to create object using C# graphics class which is painfull and not accurate. second is to export canvas as base64 which is accurate. .
Here is what i have done so far jsfiddle
here is the code giving exception

function SaveResultImage() {
  canvas.deactivateAll().renderAll();
  var base64String = canvas.toDataURL("image/jpg");
  if (!fabric.Canvas.supports('toDataURL')) {
    alert('This browser doesn\'t provide means to serialize canvas to an image');
  } else {
    console.log(base64String);
    // save image posting base64String using ajax// this is working fine
  }
}

exception: VM1226 fabric.min.js:4 Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.(…)

Aucun commentaire:

Enregistrer un commentaire