熱門文章

特殊問題處理

Q:webgl模式下讀取跨域圖片錯誤問題?
private async getTextureForWebGLByURL(url){
    return new Promise<egret.Texture>(resolve=>{
        fetch(url).then(response => response.blob()).then(blob => {
            const reader = new FileReader()
            reader.onloadend = async() => {
                resolve(<egret.Texture>await new Promise(resolve => 
                egret.BitmapData.create('base64',reader.result.split(",")[1],(bmp_data)=>{
                    let tex = new egret.Texture();
                    tex.bitmapData = bmp_data;
                    resolve(tex);
                }))); 
            };
            reader.readAsDataURL(blob)
        });
    });
}
let img = new eui.Image();
img.source = await this.getTextureForWebGLByURL('http://httpbin.org/image/jpeg');
this.addChild(img);

沒有留言:

張貼留言