Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data

后端 未结 2 1642
太阳男子
太阳男子 2021-01-03 04:29

I am getting this error in Chrome and Opera Browsers:

Uncaught SecurityError: Failed to execute \'getImageData\' on \'CanvasRenderingContext2D\': The canvas          


        
2条回答
  •  温柔的废话
    2021-01-03 05:25

    May be this will help, as you have mentioned cross origin so try this,

     var UimageObj = new Image();
    

    crossOrigin has to be set to enable the canvas data to be saved.The source image should have access-control-allow-origin set to * or a chosen domain

    UimageObj.crossOrigin = 'anonymous';   // crossOrigin attribute has to be set before setting src.If reversed, it wont work.  
    UimageObj.src = obj_data.srcUser;
    

    Hope it helps.

提交回复
热议问题