请问在加载微信的头像用哪个方法 ?

最近在做微信登录 ,但登录头像的图片拿不下来,请问是用哪个方法 ?头像的地址已经得到,但连不上去,而且会报错。

cc.textureCache.addImage(result.Obj.headimgurl, function(texture){ }

cc.loader.load(result.Obj.headimgurl,function(error,texture){ });

这两个方法 都不行,怎么破?

@jare :confused:

cc.loader.load(“http://wx.qlogo.cn/mmopen/BQxZTuuQAOOycK7Mxfj6AqR2rkpvjPL4toe0OWyMGF6vIicopJlfUMfGWTbZUwQVt9fvprxp6dZiblcomJoMRxfdFibC6mpTOD4/0.png”,function(error,texture){
// console.log(“bb”);
});

访问时出现报错~

Access to Image at ‘http://wx.qlogo.cn/mmopen/BQxZTuuQAOOycK7Mxfj6AqR2rkpvjPL4toe0OWyMGF6vIicopJlfUMfGWTbZUwQVt9fvprxp6dZiblcomJoMRxfdFibC6mpTOD4/0.png’ from origin ‘http://wx.qlogo.cn’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:7456’ is therefore not allowed access.

是不是地址太长的原因???求解

这是微信头像

http://forum.cocos.com/t/topic/41306 同求

CORS 跨域限制,你需要从自己的服务端转发,否则无法显示

1赞

http://forum.cocos.com/t/creator-webgl/36969

用了你的方法还是不行~不知道是不是微信头像地址太长的原因。。。

跨域的问题 跟长度应该没关系

现在头像读了之后,放上去按钮却是黑色的图,请问是什么原因?

@kyo7611621 功能是实现了,但用手机登录很多情况下都没有头像,或者是黑底一个~请问这个如何解决?

xhr.onreadystatechange = function () {

        if (xhr.readyState === 4 && xhr.status === 200) {
            var blob = new Uint8Array(this.response);
            var img = new Image();
            var base = "data:image/png;base64," + Base64.encode(blob);
            img.src = base;
            var spriteFrame = self.roomSelect.bt_PlayerInfo.getComponent("cc.Sprite").spriteFrame;
            var texture = new cc.Texture2D();
            // texture.generateMipmaps = false;
            texture.initWithElement(img);
            texture.handleLoadedTexture();
            var newframe = new cc.SpriteFrame(texture);
            callback(self,newframe);
        }
    };

callback(self,newframe);这个回调 是我做的,在电脑上基本没问题,但到手机就多数不行

断点查一下获取到的数据看看

11楼的意思是,
texture.initWithElement(img);
texture.handleLoadedTexture();

这两部比较好时,如果是异步的话,在还没有读完图片流,就创建了new cc.SpriteFrame(texture);

导致创建的 texture 不是完整的。

在手机浏览器上,延迟状况比较严重。

不知道官方有没有解决方案。

1赞

的确是这样的,我在回调里再去创建new cc.SpriteFrame(texture);

但在手机里基本上都是黑色的,所以想问一下如何解决@kyo7611621

一看就没仔细看帖 我那写着image.onload的得等加载完再赋值呀

image.onload

onload 有完成回调吗?

还是写个 while 循环检测?

仔细看贴啊···可能我没加缩进不明显·····

楼主。web版的微信登录怎么接?

web版的微信登录你们接了吗?求提点可否

web版的微信 怎么把显示出来?