以json形式获取二进制图像数据流并解析显示

//以json形式获取二进制图像数据流
let request = new egret.HttpRequest("games/tooth/resource/assets/avatars/2.jpg");
request.responseType = 'blob';
let url = location.protocol + "//" + location.hostname + "/tooth/getAvatar";
request.open(url,egret.HttpMethod.GET);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send();
request.addEventListener(egret.Event.COMPLETE,this.avaLoadHandler,this);
request.addEventListener(egret.IOErrorEvent.IO_ERROR,ToothUtil.onGetIOError,this);

private avaLoadHandler(evt: egret.Event): void {
    var request = evt.currentTarget;
    var blob = request.response;
    var img_url = window.URL.createObjectURL(blob);
    console.log(img_url);
    var imgLoader: egret.ImageLoader = new egret.ImageLoader;
    imgLoader.once(egret.Event.COMPLETE,this.avatarHandler,this);
    imgLoader.load(img_url);
}

private avatarHandler(evt: egret.Event): void {
    var loader: egret.ImageLoader = evt.currentTarget;
    var bmd: egret.BitmapData = loader.data;
    var bmp: egret.Bitmap = new egret.Bitmap(bmd);
    bmp.width = 32;
    bmp.height = 32;
    console.log(this.avax + ',' + this.avay);
    bmp.x = this.avax;
    bmp.y = this.avay;
    this.avay += 20;
    this.table1.addChild(bmp);
}

你可能感兴趣的:(以json形式获取二进制图像数据流并解析显示)