将BLOB读取到图像时出现Magick++错误
Magick++ Error when reading BLOB into Image
我正试图使用Magick++库将原始像素数据中的图像导出到RGBA PNG中。
然而,当我试图运行它时,我遇到了一个奇怪的错误:
terminate called after throwing an instance of 'Magick::ErrorCorruptImage'
what(): test: unexpected end-of-file `': No such file or directory @ error/rgb.c/ReadRGBImage/229
Aborted
这是相关的代码部分(我省略了填充像素向量,但这并没有改变任何东西):
#include <iostream>
#include <vector>
#include <ImageMagick/Magick++.h>
using namespace std;
int main(int argc, char *argv[]) {
Magick::InitializeMagick(*argv);
int rres, ires;
cin >> rres >> ires;
//RGBA
//rres: horiz. resolution, ires: vert. resolution
vector<unsigned char> image(rres * ires * 4);
Magick::Blob blob(&image[0], rres*ires*4);
Magick::Image img;
img.size(to_string(rres) + "x" + to_string(ires));
img.magick("RGBA");
img.read(blob);
img.write("out.png");
}
编译:
g++ --std=c++11 -O0 -g3 -ggdb3 -D_GLIBCXX_DEBUG -Wall test.cpp -o test `Magick++-config --cppflags --cxxflags --ldflags --libs`
如果您使用的是ImageMagick的Q8版本,那么您的示例就可以工作。但您似乎使用的是ImageMagick的Q16版本。后者每像素通道使用16位。您正在使用向量<无符号字符>,其仅为8位。我建议您切换到向量<无符号短>或使用向量<无符号字符>是当前大小的两倍。如果每个像素通道不需要16位,您也可以切换到ImageMagick的Q8版本。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将BLOB读取到图像时出现Magick++错误
- 线程中的Magick++分段错误