我需要从或在 Magick++中构造一个Image
对象。我已经尝试过 ImageMagick 和 GraphicsMagick,但仍然无法解决。char *
std::string
我首先创建一个Blob
对象并使用Image(const Blob &blob_)
构造函数来获取一个Image
. 这是演示代码:
//image is of type std::string
size_t len = image.size();
char *buf = new char[len + 1];
strncpy(buf, image.c_str(), len);
Blob blob(buf, len);
Image pic(blob);
但是当我运行它时,我得到了错误:
terminate called after throwing an instance of 'Magick::ErrorCoder'
what(): Magick: JPEG datastream contains no image () reported by coders/jpeg.c:344 (JPEGErrorHandler)
Aborted
我发现了一些关于从 Blob 获取字符串的信息。所以我创建了一个并通过方法Blob
更新它。base64
但是还是出现了错误。
我能想到的唯一方法是将 char 缓冲区保存在一个临时文件中,然后通过Image(const std::string &imageSpec_)
. 但是,这种方式在我的选择中确实是不必要的。