3

I have an HTML5 app that must be run locally. When I run the app and try to load image on the canvas, on Chrome I get the error message:

Unable to get image data from canvas because the canvas has been tainted by cross-origin data

Both the HTML document and the images a in the local folder. This is an app that will be distributed to users so I can't run local server. It has to be run as-is on Chrome... I have read the answers about this issue but they all relate to CORS and Cross-Orgin policy which are not relevant to local files...

What is the solution for this situation? How can I load image on canvas locally on Chrome?

EDIT: this is the code the throws the error:

var canvas = Matach.createElement(false, "canvas", false, false);           
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.globalCompositeOperation = 'source-over';

context.save();
context.drawImage(
    item.img.img, 
    -item.img.width / 2, 
    -item.img.height / 2, 
    item.img.width, 
    item.img.height
);

context.restore();

res = context.getImageData(0, 0, canvas.width, canvas.height);
Jaak Kütt
  • 2,566
  • 4
  • 31
  • 39
Light
  • 1,647
  • 3
  • 22
  • 39
  • Could you post some code? – markE Feb 26 '13 at 07:59
  • added the code. It is a part of a bigger app. – Light Feb 26 '13 at 08:22
  • Cross Origin policy _is_ relevant. It's there to ensure that local image data can't be uploaded to a remote site without explicit user direction. – Alnitak Feb 26 '13 at 08:26
  • 1
    But here it is not uploaded to a remote site. It just draws the image on the canvas on the local machine. How can it be done without an error? – Light Feb 26 '13 at 08:33

1 Answers1

-1

In chrome getimagedata has some security issues, So for using this you have to do some turnaround, Check these posts for reference, you will get the solution,

canvas getImageData doesn't work when running locally on Windows? (security exception)

Why does HTML Canvas getImageData() not return the exact same values that were just set?

Community
  • 1
  • 1
MJQ
  • 1,778
  • 6
  • 34
  • 60