Skip to content

Instantly share code, notes, and snippets.

@soundkitchen
Created May 25, 2010 15:30
Show Gist options
  • Save soundkitchen/413266 to your computer and use it in GitHub Desktop.
Save soundkitchen/413266 to your computer and use it in GitHub Desktop.
#include "testApp.h"
void testApp::setup()
{
ofAddListener(httpUtils.newResponseEvent, this, &testApp::newResponse);
httpUtils.start();
ofxHttpForm form;
form.action = "http://example.com/images/hoge.jpg";
form.method = OFX_HTTP_GET;
httpUtils.addForm(form);
}
void testApp::newResponse(ofxHttpResponse &response)
{
FIMEMORY *hmem = NULL;
FIBITMAP *bmp = NULL;
hmem = FreeImage_OpemMemory((unsigned char *)response.responseBody.c_str(),
response.responseBody.size());
if (hmem == NULL) {
ofLog(OF_LOG_ERROR, "hmem is NULL.");
return;
}
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
if (bmp == NULL) {
ofLog(OF_LOG_ERROR, "bmp is NULL.");
return;
}
FreeImage_Save(fif, bmp, ofToDataPath("thumb.jpg").c_str(), 0);
}
#include "ofMain.h"
#include "ofxHttpUtils.h"
class testApp:public ofBaseApp
{
// (snip)
private:
ofxHttpUtils httpUtils;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment