tags:

views:

212

answers:

4

Hey

I am using libcurl to download file. I download the image (JPG), but I can only save it as txt file. Is there any methods that could change data (string) to JPG and save it ?

Thanks

Edit:

How can I convert this stream ?

        Bitmap b = new Bitmap(data);
        b.Save("picture.jpg", b); <-- this gives me error
A: 

When downloading the image, you'll probably have some kind of network stream to read the data from.

I'd try to write that data to a memory stream first, then create a Bitmap on that stream (Bitmap b = new Bitmap(memStream);) and save the bitmap as JPEG file. Does that work.

Otherwise, you should really really post some source code so we can see what you're doing.

EDIT
Please edit your question when posting the source code - do not add another reply, this is not a forum software and people will get confused if you do.

Thorsten Dittmar
A: 

Look at the second parameter.

silent
+1  A: 

I think you either want

Bitmap b = new Bitmap(data);
b.Save("picture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

or just save data as it is...

ammoQ
A: 

I'm not sure why you can't save the file as .jpg.... since you are using libcurl this shouldnt be a problem:

FILE* f = _tfopen(wLocalFilePath.c_str(), _T("wb+"));
 if(!f)
  return ERROR_FILE;

 curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);

 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFileCallcack);

*Note: the code is in C++ and I'm not sure what language you are using but it should give ya a hint if you are using other languages.

wLocalFilePath is the full path of the file where you want to save your downloaded content with the extension of course for example (c:\picture.jpg) and you should open the file to write in binary mode, pass the file pointer to the curl handle along with your write callback function and you should be set.

Red Serpent