网络头像保存、加载问题

是这样,游戏里面的头像是取的微信头像,大部分的头像都是没问题的。有时候会遇到jpg格式的头像 。保存有问题。以下是代码:
有问题的头像
cocos2d::network::HttpResponseEx *response 是这个

std::vector buffer = response->getResponseData();`
auto ImagicfullPath = cocos2d::FileUtils::getInstance()->getWritablePath() + kImagicName + “.png”;
auto img = std::unique_ptrcocos2d::Image(new cocos2d::Image);
img->initWithImageData((unsigned char
)buffer->data(), buffer->size());
if (img->getData())
{
img->saveToFile(ImagicfullPath, false); //这里会出错。
}
auto pTexture= cocos2d::Director::getInstance()->getTextureCache()->addImage(img.get(), kImagicName);

下面我用pTexture 是没问题的。但是以后通过 保存的图片来创建 Sprite 会bug(IOS)。

大家有啥好的方法指导我不?