我从网络上下载一个图片到本地 然后生成一个精灵的时候出错了 ,代码如下:
FILE* fp = fopen(filefullPath.c_str(),"rb"); //获取本地图片
if (!fp)
{
return ;
}
fseek(fp,0,SEEK_END);
int len = ftell(fp);
fseek(fp,0,SEEK_SET);
char* buf = (char*)malloc(len);
fread(buf,len,1,fp);
fclose(fp);
Image* img = new Image();
img->initWithImageData((unsigned char*)buf,len);
free(buf);
Texture2D* texture = new Texture2D();
bool isImg = texture->initWithImage(img);
img->release();
if (!isImg)
{
delete texture;
return ;
}
Sprite* splashsprite = Sprite::createWithTexture(texture);
texture->release();