how to get sprite from sdcard path???


#1

i want to get sprite from sdcard

path mnt/sdcard/img.png

my code …

const char* tempTex = “mnt/sdcard/img.png”;
stringstream ss;
string s;
ss << tempTex;
ss >> s;

CCImage img;
CCFileData data(s.c_str(),“rb”);

unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
image.initWithImageData((void**)pBuffer, nSize, CCImage::kFmtJpg);
CCTexture2D**texture = new CCTexture2D();
texture->initWithImage(&image);

if( texture ) {
CCSprite *sprite = CCSprite::spriteWithTexture(texture);
}

run android

show error

Get data from file(assets//mnt/sdcard/img.png) failed!

please help me!


#2

The path should be absolute path.
May be you should change the path to “/mnt/sdcard/img.png”.


#3

I solved the problem.

I Use to fopen