我正在使用 Leptonica 库来处理一些图片。之后我想在我的 QT GUI 中显示它们。Leptonica 使用他们自己的图像格式 Pix,而 QT 使用他们自己的格式 QPixmap。目前对我来说唯一的方法是将处理后的图片保存为文件(如 bmp ),然后使用 QT 函数调用再次加载它们。现在我想在我的代码中转换它们,所以我不需要绕道将它们保存在文件系统上。任何想法如何做到这一点?
最好的祝福
// 编辑:
好的,正如已经建议的那样,我尝试将 PIX* 转换为 QImage。PIX* 的定义如下:
http://tpgit.github.com/Leptonica/pix_8h_source.html
struct Pix
{
l_uint32 w; /* width in pixels */
l_uint32 h; /* height in pixels */
l_uint32 d; /* depth in bits */
l_uint32 wpl; /* 32-bit words/line */
l_uint32 refcount; /* reference count (1 if no clones) */
l_int32 xres; /* image res (ppi) in x direction */
/* (use 0 if unknown) */
l_int32 yres; /* image res (ppi) in y direction */
/* (use 0 if unknown) */
l_int32 informat; /* input file format, IFF_* */
char *text; /* text string associated with pix */
struct PixColormap *colormap; /* colormap (may be null) */
l_uint32 *data; /* the image data */
};
而 QImage 为我提供了这样的方法:
http://developer.qt.nokia.com/doc/qt-4.8/qimage.html#QImage-7
QImage ( const uchar * data,
int width,
int height,
int bytesPerLine,
Format format )
我假设在调用构造函数时我不能只将数据从 PIX 复制到 QImage。我想我需要逐个像素地填充 QImage 像素,但实际上我不知道怎么做?我需要遍历所有坐标吗?我如何看待位深?这里有什么想法吗?