关于使用XMLHttpRequest下载图片一张图片显示不了

使用以下代码从网络上下载图片内容后,怎么把图片流赋值给精灵啊
var xhr = cc.loader.getXMLHttpRequest();
var thisVar = this;
xhr.onreadystatechange = function () {
var arraybuffer = xhr.response;
cc.log('arraybuffer is ’ + arraybuffer);
var temp = new cc.SpriteFrame;
temp = arraybuffer;
thisVar.img.getComponent(cc.Sprite).spriteFrame = temp;
};
xhr.timeout = 3000;
xhr.responseType = “arraybuffer”;
var myDate = new Date();
//var url = config.g_HttpUrl + “Image/DownLoadImage.ashx”;
var url = “http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx”;
cc.log(url);
xhr.open(“GET”, encodeURI(url), true);
xhr.send();

你们可以看看 http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx 这个链接打开就是一张图片的,但是代码里取不出来,设置了无效

没人回复吗

有可能跨域

不可能是跨域,我是想用 getXMLHttpRequest 自己从http服务里取出图片数据

var self = this;
cc.loader.load(headimgurl, function (err, texture) {
if (err) {
cc.log(err);
}
self.headimg.spriteFrame = new cc.SpriteFrame(texture);
});

相关你可以找如何在ccc里使用微信头像

var self = this;
cc.loader.load(“http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx”, function (err, texture) {
if (err) {
cc.log(err);
}
self.img.spriteFrame = new cc.SpriteFrame(texture);
});

提示这个错误
Simulator: Error: Download text failed: http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx

提示错误,url链接却能打开,怎么回事?

你的服务器是不是要加上这个类型的文件识别?

用抓包工具看了,这个服务器是支持跨域的并且已经指定了文件类型是图片。只是url后缀不是jpg之类的而已

var self = this;
var config = {id:“http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx",type:"png”};
cc.loader.load(config, function (err, texture) {
if (err) {
cc.log(err);
}
self.img.spriteFrame = new cc.SpriteFrame(texture);
});
这样也不行的话就不知道怎么搞了

var self = this;
var urlcon = {id:“http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx",type:"png”};
cc.loader.load(urlcon, function (err, texture) {
if (err) {
cc.log(err);
}
self.img.spriteFrame = new cc.SpriteFrame(texture);
});
这样的代码提示
Simulator: Error: Load image failed: http://61.36.72.42/phoneDdService/Image/DownLoadImage.ashx

是不是指定了png实际发下来的图片是jpg?
但是这个链接再ie里能打开啊

或者用 getXMLHttpRequest 自己怎么把图片数据取出来再转换成图片显示在ccsprite里啊,不用官方封装的load了

不要撤销啊,不然我重发一贴:如何显示一个url的图片

我们也用过这种类型的图片,我们是php那边给返回的,我对比了下,就返回头存在一些差异,我猜可能是服务器那边没配置好吧

这个服务是我写的,需要添加什么我都能写进去,加了文件类型,跨域支持 还缺什么?

这是我们的,正常
这是你的