我正在将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是每像素1位的图像,并且是从QPixMap派生的。换句话说,您可以将其直接传递给brush1。无需对其进行任何其他操作(正确填充除外),即:
QBitmap bmp = QBitmap::FromData( QSize( 4, 4 ), fill );
brush1.setTexture(bmp);
在Windows下和在其他平台上一样,这应该也能正常工作...
编辑:值得注意的是,在上述两种情况下,都没有4条短裤的意义。 1 short是16位。 4 x 4 1位像素是16位,因此无论如何它只读取第一个短消息。
关于c++ - 来自QBitmap的QPixmap,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2274395/