我正在转换 win32 api 图形库以使用 qt图书馆代替。我已经成功地在 XP 上编译,现在要测试新的和改进的图形库的真正跨平台能力,我正在尝试在 Ubuntu (9.10) 上构建它。
我遇到了几个编译时错误 - 因为有些类是 Windows 特定的,所以我需要再次修改代码。
我有一段代码如下所示:
//original code (compiled succesfully under Windows)
unsigned short fill[4];
fill[0] = (unsigned short)(pattern & 0xF000) >> 8;
fill[1] = (unsigned short)(pattern & 0x0F00) >> 4;
fill[2] = (unsigned short)(pattern & 0x00F0);
fill[3] = (unsigned short)(pattern & 0x000F) >> 4;
HBITMAP hbmp = CreateBitmap(4, 4, 1, 1, fill);
QPixmap texture;
texture.fromWinHBITMAP(hbmp);
DeleteObject(hbmp);
brush1.setTexture(texture);
//Code to compile on Ubuntu
unsigned short fill[4];
fill[0] = (unsigned short)(pattern & 0xF000) >> 8;
fill[1] = (unsigned short)(pattern & 0x0F00) >> 4;
fill[2] = (unsigned short)(pattern & 0x00F0);
fill[3] = (unsigned short)(pattern & 0x000F) >> 4;
QBitmap bmp(4, 4, fill); //Is this correct ?
QPixmap texture;
texture.fromWinHBITMAP(bmp); // How to convert QBitmap to QPixmap ?
//DeleteObject(hbmp); // No longer required (local object scope)
brush1.setTexture(texture);
最佳答案
QBitmap是一个QPixmap,它继承了这个类。
关于c++ - 来自 QBitmap 的 QPixmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2274395/