将 Leptonica Pix 对象转换为 QPixmap (或其他图像对象)
我正在使用 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,但实际上我不知道如何?我需要循环遍历所有坐标吗?如何看待位深度?这里有什么想法吗?
I'm using the Leptonica Library to process some pictures. After that I want to show them in my QT GUI. Leptonica is using their own format Pix for the images, while QT is using their own format QPixmap. At the moment the only way for me is to save the pictures after processing as a file ( like bmp ) and then load them again with a QT function call. Now I want to convert them in my code, so I dont need to take the detour with saving them on the filesystem. Any ideas how to do this?
Best Regards
// edit:
Okay as already suggested I tried to convert the PIX* to a QImage.
The PIX* is defined like this:
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 */
};
while QImage offers me a method like this:
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 )
I assume I cant just copy the data from the PIX to the QImage when calling the constructor. I guess I need to fill the QImage Pixel by Pixel, but actually I dont know how? Do I need to loop through all the coordinates? How do I regard the bit depth? Any ideas here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用将QImage转换为PIX:
这用于将 PIX 转换为 QImage:
I use this for conversion QImage to PIX:
And this for conversion PIX to QImage:
此代码接受
const QImage&
参数。This code accepts a
const QImage&
parameter.我不知道 Leptonica 库,但我简单浏览了一下文档,找到了有关 的文档PIX结构。您可以从原始数据创建 QImage并将其转换为 QPixmap convertFromImage。
I do not know the Leptonica Library, but I had a short look at the documentation and found the documentation about the PIX structure. You can create a QImage from the raw data and convert this to a QPixmap with convertFromImage.
好吧,我可以这样解决问题:
Leptonica 提供了一个函数
,使用这个函数你可以写入内存而不是文件流。尽管如此(在本例中)Bmp 标头和格式仍然存在(其他图像格式也有相同的功能)。
QT 的相应函数是这样的:
由于 Header 仍然存在,我只需要将数据 ptr 和大小传递给 loadFromData 函数,QT 就会完成其余的工作。
所以总的来说,它会是这样的:
这实际上对我有用,但我不知道是否有一种方法可以如此简单地向后执行此操作。 (如果有,请告诉我)
最好的问候
Well I could solve the problem this way:
Leptonica offers a function
With this function you can write into the memory instead of a filestream. Still ( in this example ) the Bmp Header and format persists ( there are the same functions for other image formats too ).
The corresponding function from QT is this one:
Since the the Header persits I just need to pass the data ptr and the size to the loadFromData function and QT does the rest.
So all together it would be like this:
This actually works for me, tho I don't know if there is a way to do this backwards so easy. ( If there is, please let me know )
Best Regards
您可以将像素图保存到 RAM 而不是文件(使用 QByteArray 来存储数据,使用 QBuffer 作为 I/O 设备)。
You can save your pixmap to RAM instead of file (use QByteArray to store the data, and QBuffer as your I/O device).