我正在使用Leptonica庫來處理一些圖片。之後,我想在我的QT GUI中展示它們。 Leptonica使用自己的格式Pix來處理圖像,而QT使用自己的格式QPixmap。目前唯一的方法是將處理後的圖片保存爲文件(如bmp),然後再用QT函數調用再次加載它們。現在我想在我的代碼中將它們轉換,所以我不需要繞道將它們保存在文件系統中。任何想法如何做到這一點?將Leptonica Pix對象轉換爲QPixmap(或其他圖像對象)
問候
//編輯:
沒關係,已經建議我嘗試在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。我想我需要由Pixel填充QImage Pixel,但實際上我不知道如何?我是否需要遍歷所有座標?我如何看待比特深度?這裏的任何想法?
嗯謝謝你 - 我想這個工作,但實際上我有點困惑 - >看我的問題 – Toby
更新如果你是幸運的,你應該能夠鑄造它使用Pix.data到一個uchar *:reinterpret_cast(Pix.data)。您必須調整QImage構造函數的Format參數(嘗試QImage :: Format_RGB32或QImage :: Format_ARGB32)。如果您不幸運行,則必須首先創建一個大小爲PIX.wpl * h的新緩衝區,並通過從PIX.data中讀取l_uint32並將它們分爲四個字節(對於R,G,B,A)逐字節複製像素值)通過掩蔽和移位。 –
hmuelner
哈好吧我知道了 - 做了一點不同(因爲有一個功能可以做交易) - 但仍然,沒有你建議我使用QImage之前使用QPixmap我也許wouldnt找到它! – Toby