Is it possible to use remote images in ccui.ImageView?

Is it possible somehow to download remote image during program execution and place it in ccui.ImageView?

No, you might need to implement it by yourself.

We do have remote image loading.

@owen :smile: Advantage exclusive to Cocos2d-JS

Please refer to RemoteTextureTest in TextureCache Test in the test case. And for a brief usage:

cc.textureCache.addImage("http://www.cocos2d-x.org/attachments/download/1508", function(texture) {
    if (texture instanceof cc.Texture2D) {
        cc.log("Remote texture loaded: " + this._remoteTex);
        var sprite = new cc.Sprite(texture);
        sprite.x = cc.winSize.width/2;
        sprite.y = cc.winSize.height/2;
        somenode.addChild(this._sprite);
    }
    else {
        cc.log("Fail to load remote texture");
    }
});
2 Likes

@pandamicro
Cool! Thanks for pointing out this nice feature.

Hi,

the example you put is working perfectly, so I am trying to use the same method to load facebook profile picture, but same code failed to do that and I am getting the error "can not load http://graph.facebook.com/xxxxxxx/picture?type=square&height=200&width=200"

any idea how can I overcome this issue and load FB profile pics.

I suppose the Facebook graph API should be https address
Unfortunately, the https protocol is not until supported.

:frowning: sad to know
is there any other way to achieve the same, pleaase I badly need this?

I tried Facebook SDK, but the OpenGraph API /me/picture only gives me the address which is also under https.

https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%2Fpicture&version=v2.1

I suppose you can retrieve the image on your own server and download it from your http server.

The problem that I am using a game backend service, so this solution is not possible for me, do you think there is a plan to support this in the next release of cocos-js?

Absolutely, it won’t be resolved for 3.1, as 3.1 is now closed for new features, but we will support https connection in a future version

Yes, but how use cc.Texture2D in ccui.ImageView? It seems that loadTexture method doesn’t support loading of cc.Texture2D

Its cool , i tried it was working…

just change the https to http… it should work

I’ve followed all your code, and remote texture loading worked on native target, but failed on html5 browser. Is it a bug?

I am using cocos2d-js 3.3, and I still can’t load the image url with https. The problem did not resolve yet? Any work around?

I did that:

loadImage: function (callback) {

    var url = 'http://your/url/to/image must have no ? and params';
    
    try {
        var ret = cc.textureCache.addImage(url, function (texture) {
            callback(null);
        }, this);
    } catch (ex) {
        throw new Errors.ImageNotLoadedError(ex+': '+url);
    }
},

and then

    this.image.loadTexture(url, ccui.Widget.LOCAL_TEXTURE);

but later I switched to cocos2d-x and now I’m using c++ to load and show images

I tried you code. However, when I tried to load an image url with https (facebook profile picture), the app crashed.

Possibly https is not supported by cocos2d now. You can google more

I needed this in cocos2d-x c++ so I built this class, it does the job for my use-cases.

Awesome! Thanks.

Thank you for your code. I implemented it into the CCSprite class(c++) in cocos2d-js and it works.