2

我需要导入 PNG 并将其显示在 Motif 应用程序的屏幕上。出于我自己最熟悉的原因,我不想使用比我需要的更多的库,我只想坚持使用 Motif 和 pnglib。

我已经为此奋斗了几天,我想放下我的骄傲并寻求一些帮助。此屏幕截图显示了问题:

https://s3.amazonaws.com/gtrebol264929/pnglib_fail.png

右边的窗口显示图像应该是什么样子,左边的窗口是我的 Motif 应用程序,显示它在我的应用程序中的样子。显然我已经得到了图像数据,因为可以看到图片的基本概念。但也很明显,我搞砸了如何将像素数据从 pnglib 获取到 XImage 中。下面是我的代码:

char * xdata = malloc(width * height * (channels + 1));
memset(xdata,100,width * height * channels);    

int colc = 0;
int bytec = 0;
while (colc < width) {
    int rowc = 0;
    while(rowc < height) {
        png_byte * row = png.row_pointers[rowc];
        memcpy(&xdata[bytec],&row[colc],1);
        bytec += 4;

        rowc += 1;
    }
    colc += 1;
}



XImage * img = XCreateImage(display, CopyFromParent, depth * channels, ZPixmap, 0, xdata, width, height, 32, bytes_per_line);
printf("PNG %ix%i (depth: %i x %i) img: %p\n",width,height,depth,channels,img);


XPutImage (display, win, gc, img, 0, 0, 0, 0, width, height); // 0, 0, 0, 0 are src x,y and dst x,y

png.row_pointers 是来自 pnglib 的像素数据。

我很确定我只是误解了像素数据的存储方式,但我不能完全弄清楚我做错了什么。很感谢任何形式的帮助。

一切顺利

加里

4

0 回答 0