c++ - 来自 QBitmap 的 QPixmap

标签 c++ qt winapi gdi

我正在转换 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/

相关文章:

c++ - 无法从 Arduino 读取数据到 C++ 程序

c++ - 我怎么知道有多少客户端连接到我的服务器与 Qt

c++ - 在OpenGL中用鼠标拾取在3D空间中拖动3D点的最佳方法?

c++ - 使用 show() 只打开一个 QDialog 实例,如果我关闭 QDialog,对象是否也被删除

c++ - QT - 现有插槽在 mainwidow.cpp 中不可见

c++ - 为什么虚拟WndProc没有被调用?

c++ - Mac 上的 Visual Studio 使用 VS2015 故障性能测试--Z : not considered a local drive

c++ - QByteArray::number(int) 只有两个字节长

c++ - 另一个win32问题

c# - 如何调用 AnimateWindow 函数来为外部窗口/进程设置动画