Hi everyone,
I have a problem with saving image file from url. I use HttpClient to get buffer from url and save that data to image with cocos2d::Image.
I realize sometimes the size of saved image is different from that original image. And its quality always change if the image has complex effect such as blur, glow…
Has anyone encountered this problem yet?
Here is two image. (The first one is original).
Here is the url which i downloaded from: image url
And here my code:
HttpRequest *request = new HttpRequest();
request->setRequestType(HttpRequest::Type::GET);
request->setUrl("http://lh3.googleusercontent.com/-Xp0x0s7uBFs/VVCu2OSAzxI/AAAAAAAAAHQ/owxv73d2tlc/s640/StylzzZ%252520%252528263%252529.png");
request->setResponseCallback([](HttpClient *client, HttpResponse *response) {
if (response->isSucceed()) {
auto data = response->getResponseData();
Image *img = new Image();
if (img->initWithImageData(reinterpret_cast<const unsigned char*>(&(data->front())), data->size())) {
if (img->saveToFile("xxx.png", false)){
img->release();
}
}
}
});
HttpClient::getInstance()->send(request);
request->release();
Thanks!!!
P.s: I also try to save image with RenderTexture, and I got the same result. I wonder the problem is response data or me miss something when use “saveToFile”. Sorry for my bad English. Hope you get my point.