[英]Initialize Magick++ from stream buffer in C++
I can't seem to find an example of the proper syntax/method for initializing an ImageMagick Magick++ object from an iostream stream_buffer in C++. 我似乎找不到用于从C ++中的iostream stream_buffer初始化ImageMagick Magick ++对象的正确语法/方法的示例。
I'm trying to use the result from an aws sdk getObject which seems to return a stream buffer to push into ImageMagick to create thumbnails via lambda on demand. 我正在尝试使用aws sdk getObject的结果,该结果似乎返回一个流缓冲区以推入ImageMagick以根据需要通过lambda创建缩略图。
example of the relevant code from the aws-sdk-cpp I'm using to retrieve the object: 我用来检索对象的aws-sdk-cpp中相关代码的示例:
auto get_object_outcome = s3_client.GetObject(object_request);
if (get_object_outcome.IsSuccess())
{
// Get an Aws::IOStream reference to the retrieved file
auto &retrieved_file = get_object_outcome.GetResultWithOwnership().GetBody();
// read the object's contents and write to a file
std::ofstream output_file(file_name, std::ios::binary);
output_file << retrieved_file.rdbuf();
return true;
}
else
{
auto error = get_object_outcome.GetError();
std::cout << "ERROR: " << error.GetExceptionName() << ": "
<< error.GetMessage() << std::endl;
return false;
}
Any help is appreciated - new to c++ so I'm not yet versed in converting more advanced data formats such as streams/blobs/buffers. 感谢您的帮助-C ++的新功能,因此我还不熟悉转换更高级的数据格式,例如流/ blob /缓冲区。
I try taking your retrieved_file, copy it into a std::vector, create an magick blob, create an image from the blob: 我尝试将您的restored_file拷贝到std :: vector中,创建magick blob,然后从blob中创建图像:
// create an empty buffer
std::vector<char> buffer;
// file your buffer with the retrieved file
std::copy(istream_iterator(retrieved_file), istream_iterator(), std::back_inserter(buffer));
// create a Magick++ blob with your data
Blob my_blob(buffer.data(), buffer.size());
// create a Magick++ image from your blob
Image image_from_blob(my_blob);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.