当前位置:   article > 正文

creator项目里的图片转base64_cocos creator 图像base64转码

cocos creator 图像base64转码

creator项目里的图片转base64

  1. //获取指定图片地址的base64值,
  2. function getBase64Image(url, callback){
  3. var canvas = document.createElement("CANVAS");
  4. var ctx = canvas.getContext('2d');
  5. var img = new Image;
  6. img.crossOrigin = 'Anonymous';
  7. img.src = 'res/raw-assets/' + url;//如:'res/raw-assets/' + "public/skin/frame_1.png"
  8. img.onload = function(){
  9. canvas.height = img.height;
  10. canvas.width = img.width;
  11. ctx.drawImage(img, 0, 0);
  12. var dataURL = canvas.toDataURL('image/png');
  13. canvas = null;
  14. if( callback ) callback(dataURL);
  15. }
  16. }

转自:https://forum.cocos.org/t/web-resources-base64/60759

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/152418
推荐阅读
相关标签
  

闽ICP备14008679号