Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyway to get array bytes/base64 of image from CCSprite/CCImage/CCTexture2d? #11584

Closed
0xJimmyBeh opened this issue Apr 24, 2015 · 3 comments
Closed

Comments

@0xJimmyBeh
Copy link

As title,
I need the array bytes/base64 of image to upload it to server, but i can't find any solution yet.
I tried CCImage.getData() in JSB but return null.

I'm using this custom Image Picker to get the image from photo album.
It successfully created CCSprite with the return texture.
#11344

After get the array bytes/base64 of image, i need to use it in JSB with Cocos2d-JS.

Thanks.

@zilongshanren
Copy link
Member

@Zinitter
You might need to maintain a key-value map of texture file name and texture.
Every time you want to get the Image of Texture, you could use this map to query the texture file name and create CCImage with this name.

@walzer
Copy link
Contributor

walzer commented Apr 24, 2015

Duplicated with #11349
Let's track that issue and close this one.

@walzer walzer closed this as completed Apr 24, 2015
@0xJimmyBeh
Copy link
Author

@AndyQue

Are you suggesting me to maintain a key-value map of texture so i can recreate the CCImage?
Then does the CCImage.getData() can return the image array bytes?

I have tried modified the ImagePicker to return CCImage instead of texture and tested it with the JSB in Cocos2d-JS

var texture = new cc.Texture2D();
texture.initWithImage(returnCCImage);

var sprite = new cc.Sprite(texture);
cc.log("data : " + returnCCImage.getData());<-- this show null on log

The sprite can be created and show properly on Mac and iOS with the return CCImage.
The Android show a black sprite but size of sprite it correct, not sure my modification is correct or not.

returnCCImage.getData() on Mac and iOS showing null and Android will crashed.

Am i doing something wrong or is the bug on the CCImage.getData()?

Updated :
Can you have a look on this ImagePicker implementation
https://github.com/qiankanglai/ImagePicker

Is it possible to modify the code to return
cocos2d::Texture2D and array bytes of image in ImagePicker::finishImage included JSB?

I'm not very understand about the array bytes and not sure what type/class should be use.

This become more complicated when on JSB, i have no idea how to modify the JSB.
Does array bytes should be a uint32_t or uint8_t?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants