作者Josh770424 (Josh Bourne)
看板C_and_CPP
標題[問題] 如何使用VC搭配CURL抓圖片 存放在記憶體
時間Mon Sep 5 16:50:10 2011
開發平台(Platform): VC++
額外使用到的函數庫(Library Used): OPENCV CURL
問題(Question):目前使用CURL來抓取網頁上的圖片,
想請問抓到的圖片內容如何存在陣列
或是記憶體內,而不是用FOPEN存起來,
先謝謝各位解答!
部份利用CURL抓圖的程式碼:
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl;
curl = curl_easy_init();
FILE * output = fopen("C:\\1.jpg","wb");
curl_easy_setopt(curl, CURLOPT_URL,"http:xxx.jpg");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void * )output);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(output);
size_t WriteCallback(void * ptr, size_t size, size_t nmemb, void *data)
{
size_t totalSize = size*nmemb;
fwrite(ptr,totalSize,1,(FILE * )data);
return totalSize;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.112.2
→ littleshan:改寫你的 WriteCallback 呀 09/05 17:29
→ Josh770424:您好,能不能大致上講解一下如何改寫?謝謝 09/05 17:34
→ littleshan:fwrite是把資料寫進檔案,__則是把資料寫進另一個陣列 09/05 17:38
→ littleshan:空格請自已找適合的答案填進去 09/05 17:38