重定向卷曲库函数的输出到图像文件

问题描述:

我使用curl库相机做旋转操作。重定向卷曲库函数的输出到图像文件

以下是我迄今所做的:现在

#include <iostream>   // For std::cerr 
#include <string>   // For std::string,getline(),c_str() 

#include <curl/curl.h>  // For curl library functions like curl_easy_setopt,curl_easy_perform etc. 

class camera_image_rotate { 
    CURL *curl = curl_easy_init(); 
    std::string ipaddress,username,password,url; 
    int rotation; 
    CURLcode res; 
    public: 
    camera_image_rotate(int x) : rotation(x) { 
     std::cout<<"Enter ip address: "; 
     getline(std::cin,ipaddress); 
     std::cout<<"Enter username: ";  
     getline(std::cin,username); 
     username+=":"; 
     std::cout<<username<<'\n'; 
     std::cout<<"Enter password: "; 
     getline(std::cin,password); 
     password+="@"; 
     std::cout<<password<<'\n'; 
     ipaddress+="/axis-cgi/jpg/image.cgi?rotation="; 
     ipaddress+=std::to_string(rotation); 
     std::cout<<ipaddress<<'\n'; 
     url=username+password+ipaddress; 
    } 
    void rotate() { 
     if(curl) { 
      res=curl_easy_setopt(curl,CURLOPT_URL,url.c_str()); 
      res=curl_easy_perform(curl); 
      if(res!=CURLE_OK) 
       std::cerr<<"Oops, Invalid IP"; 
     } 
     else { 
      std::cerr<<"Something went wrong"; 
     } 
    } 
    ~camera_image_rotate() { 
     if(res==CURLE_OK) 
      curl_easy_cleanup(curl); 
    } 
}; 

int main() { 
    camera_image_rotate s(90); 
    s.rotate(); 
} 

,我所面临的问题是,当我执行该程序尝试打印在控制台上的旋转图像,所以我完全得到一些 不可读的输出。所以,我想将此程序的输出重定向到* .jpg或* .png文件。我如何实现这一目标?我在他们的官方网站上提到了关于CURL的文档 ,但是我没有找到任何有用的东西。

我使用Ubuntu OS &铛++ 3.8.0编译器。

+0

在本文档中,没有什么关于与接收到的数据将被调用的回调?我确定有! –

+0

这是C例如https://stackoverflow.com/a/1636415/8491726我敢肯定,你就可以把它转换为C++使用流 –

你可能寻找CURLOPT_WRITEFUNCTION回调被调用与下载的所有数据。 (一次一小片。)

在简单的情况下,你还可以逃脱默认写入功能,只需设置​​到一个文件中。

您还可以通过查看示例(如getinmemory.c) - 使用回调接收传输的全部内容到内存中,来了解回调的工作方式。