egret内base64图片和texture bitmap互转的方法
参考文献
http://bbs.egret-labs.org/thread-5929-1-1.html
http://edn.egret.com/cn/docs/page/500
[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]
var texture: egret.Texture = RES.getRes("egretIcon");
var img: HTMLImageElement = texture.bitmapData;
var tmp: HTMLCanvasElement = document.createElement("canvas");
tmp.width = img.width;
tmp.height = img.height;
tmp.getContext("2d").drawImage(img, 0, 0, img.width, img.height);
var base64img: string = tmp.toDataURL("image/png");
alert(base64img);
[/pcsh]
[pcsh lang="js" tab_size="4" message="" hl_lines="" provider="manual"]
var img2: HTMLImageElement = new Image();
img2.onload = () => { //图片加载完成
var texture2: egret.Texture = new egret.Texture();
texture2._setBitmapData(img2); //方法未开放。
var testBitmap: egret.Bitmap = new egret.Bitmap(texture2); //测试
testBitmap.x = testBitmap.y = 50;
this.addChild(testBitmap);
};
img2.src = base64img; //开始加载
[/pcsh]
最后更新于 2017-03-17 15:58:08 并被添加「」标签,已有 751 位童鞋阅读过。
此处评论已关闭