Problem creating sprite from image in internal storage

Hello guys,

I’m trying to create a sprite using an image saved in my application internal data storage, but all i get is a black image.
To clarify I save an image at runtime in the folder /data/data/com.app.packagename/ and try to create a sprite from it by using:

CCSprite::create(FILEPATH);

I debugged the code to see what it is happening and I see that the file is found, it reaches the class CCTextureCache passes over this line:

unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), "rb", &nSize);

When I go inside the method getFileData it goes through fopen / fclose and it seems to work correctly because I can see some data in the variable pData and size.

Anyway it completes all the steps from the method CCSprite::create(const char* pFilePath).

Does anyone know if its possible to create an sprite at runtime based on an image from internal storage? Have everyone ever tried?
I don’t know if it is a bug or what I’m doing wrong, the thing is that all I get is a black image and I don’t have any clue where is the error.

I have already checked if the file saved in the /data/data/com.app.packagename/ folder is correct by creating an ImageView and placing it on it and it’s correct. So the problem is not in the file itseft but in the way cocos2d-x is creating the sprite.

Thanks in advance. Any help will be appreciated.

I realized that if I back out of the program say by hitting home and then retapping the programs icon the image is actually loaded. It’s like it doesn’t fully draw on first time around. Did you ever figure out the final solution.

Mike M wrote:

I realized that if I back out of the program say by hitting home and then retapping the programs icon the image is actually loaded. It’s like it doesn’t fully draw on first time around. Did you ever figure out the final solution.

Yes Mike. I got it working. It has something to do with the cycle of Cocos2d-x. That’s why when you hit home and come back the image is loaded. I solved this problem by delaying my method that creates the sprite based on the image in one cycle using:

scheduleOnce(schedule_selector(PhotoPage::callbackPhotoDidSave), 0);

where callbackPhotoDidSave is the method that creates the sprite based on the image.

Hope this is clear!

Love simple solutions to silly problems. Thanks a bunch. I have had a black image appearing for oh I don’t know 3 hours now and just finally noticed the refresh when I accidentally tapped home and went back into the app. So the fact that you saved me another few hours of trying to figure out a solution for this issue is awesome.

Mike M wrote:

Love simple solutions to silly problems. Thanks a bunch. I have had a black image appearing for oh I don’t know 3 hours now and just finally noticed the refresh when I accidentally tapped home and went back into the app. So the fact that you saved me another few hours of trying to figure out a solution for this issue is awesome.

You are welcome! I’m glad I could help.

Any idea why the image is flipped vertically and horizontally?

Mike M wrote:

Any idea why the image is flipped vertically and horizontally?

In my case the image is normally displayed. Are you getting the image from a camera preview? If so, maybe there is something to do with your camera configuration, otherwise I don’t know what it might be. Are you sure the original image is not flipped?