2013-02-26 89 views
3

我有一個必須在本地運行的HTML5應用程序。當我運行應用程序並嘗試加載在畫布上的圖像,在Chrome我得到的錯誤信息:使用Chrome在本地畫布上繪製圖像

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

無論是HTML文件和本地文件夾的圖像。 這是一個應用程序,將分發給用戶,所以我不能運行本地服務器。它必須在Chrome上運行... 我已閱讀有關此問題的答案,但它們都與CORS和Cross-Orgin政策有關,這些政策與本地文件無關...

什麼是解決這種情況?我如何在Chrome上本地加載圖像?

編輯: 這是引發錯誤的代碼:

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); 
+0

你可以張貼一些代碼? – markE 2013-02-26 07:59:23

+0

添加了代碼。它是一個更大的應用程序的一部分。 – Light 2013-02-26 08:22:07

+0

Cross Origin策略_is_有關。這是爲了確保本地圖像數據無法在沒有明確的用戶指導的情況下上傳到遠程站點。 – Alnitak 2013-02-26 08:26:30

回答