62 #if defined(Q_WS_WINCE) 70 #define CAPTUREBLT ((DWORD)0x40000000) 78 GetClientRect(winId, &r);
80 if (w < 0) w = r.right - r.left;
81 if (h < 0) h = r.bottom - r.top;
86 if (qobject_cast<QDesktopWidget *>(widget)) {
87 RECT
rect = {0,0,0,0};
88 AdjustWindowRectEx(&rect, WS_BORDER | WS_CAPTION,
FALSE, 0);
90 y += rect.top - magicNumber;
96 HDC display_dc = GetDC(0);
97 HDC bitmap_dc = CreateCompatibleDC(display_dc);
98 HBITMAP bitmap = CreateCompatibleBitmap(display_dc, w, h);
99 HGDIOBJ null_bitmap = SelectObject(bitmap_dc, bitmap);
102 HDC window_dc = GetDC(winId);
103 BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY
110 ReleaseDC(winId, window_dc);
111 SelectObject(bitmap_dc, null_bitmap);
116 DeleteObject(bitmap);
117 ReleaseDC(0, display_dc);
133 HDC display_dc = GetDC(0);
137 memset(&bmi, 0,
sizeof(bmi));
138 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
139 bmi.bmiHeader.biWidth = w;
140 bmi.bmiHeader.biHeight = -h;
141 bmi.bmiHeader.biPlanes = 1;
142 bmi.bmiHeader.biBitCount = 32;
143 bmi.bmiHeader.biCompression = BI_RGB;
144 bmi.bmiHeader.biSizeImage = w * h * 4;
148 bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (
void **) &pixels, 0, 0);
149 ReleaseDC(0, display_dc);
151 qErrnoWarning(
"QPixmap::toWinHBITMAP(), failed to create dibsection");
155 qErrnoWarning(
"QPixmap::toWinHBITMAP(), did not allocate pixel data");
166 int bytes_per_line = w * 4;
167 for (
int y=0; y<h; ++y)
168 memcpy(pixels + y * bytes_per_line, image.
scanLine(y), bytes_per_line);
174 return QPixmap(data).toWinHBITMAP(format);
183 memset(&bitmap_info, 0,
sizeof(BITMAP));
185 int res = GetObject(bitmap,
sizeof(BITMAP), &bitmap_info);
187 qErrnoWarning(
"QPixmap::fromWinHBITMAP(), failed to get bitmap info");
190 int w = bitmap_info.bmWidth;
191 int h = bitmap_info.bmHeight;
194 memset(&bmi, 0,
sizeof(bmi));
195 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
196 bmi.bmiHeader.biWidth = w;
197 bmi.bmiHeader.biHeight = -h;
198 bmi.bmiHeader.biPlanes = 1;
199 bmi.bmiHeader.biBitCount = 32;
200 bmi.bmiHeader.biCompression = BI_RGB;
201 bmi.bmiHeader.biSizeImage = w * h * 4;
207 HDC display_dc = GetDC(0);
208 if (
GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
218 QImage image(w, h, imageFormat);
220 int bytes_per_line = w *
sizeof(
QRgb);
221 for (
int y=0; y<h; ++y) {
223 const QRgb *src = (
const QRgb *) (data + y * bytes_per_line);
224 for (
int x=0; x<w; ++x) {
225 const uint pixel = src[x];
226 if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0)
227 dest[x] = pixel | 0xff000000;
229 dest[x] = pixel |
mask;
235 qWarning(
"QPixmap::fromWinHBITMAP(), failed to get bitmap bits");
237 ReleaseDC(0, display_dc);
247 int bpl = ((w+15)/16)*2;
250 for (
int y=0; y<h; y++)
251 memcpy(bits+y*bpl, bm.
scanLine(y), bpl);
252 HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
260 if (maskBitmap.
isNull()) {
272 HICON hIcon = CreateIconIndirect(&ii);
274 DeleteObject(ii.hbmColor);
275 DeleteObject(ii.hbmMask);
283 static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap,
int w,
int h)
286 memset(&bmi, 0,
sizeof(bmi));
287 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
288 bmi.bmiHeader.biWidth = w;
289 bmi.bmiHeader.biHeight = -h;
290 bmi.bmiHeader.biPlanes = 1;
291 bmi.bmiHeader.biBitCount = 32;
292 bmi.bmiHeader.biCompression = BI_RGB;
293 bmi.bmiHeader.biSizeImage = w * h * 4;
302 if (
GetDIBits(hdc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
304 for (
int y=0; y<h; ++y) {
305 void *dest = (
void *) image.
scanLine(y);
310 qWarning(
"qt_fromWinHBITMAP(), failed to get bitmap bits");
319 bool foundAlpha =
false;
320 HDC screenDevice = GetDC(0);
321 HDC hdc = CreateCompatibleDC(screenDevice);
322 ReleaseDC(0, screenDevice);
325 bool result = GetIconInfo(icon, &iconinfo);
327 qWarning(
"QPixmap::fromWinHICON(), failed to GetIconInfo()");
329 int w = iconinfo.xHotspot * 2;
330 int h = iconinfo.yHotspot * 2;
332 BITMAPINFOHEADER bitmapInfo;
333 bitmapInfo.biSize =
sizeof(BITMAPINFOHEADER);
334 bitmapInfo.biWidth = w;
335 bitmapInfo.biHeight = h;
336 bitmapInfo.biPlanes = 1;
337 bitmapInfo.biBitCount = 32;
338 bitmapInfo.biCompression = BI_RGB;
339 bitmapInfo.biSizeImage = 0;
340 bitmapInfo.biXPelsPerMeter = 0;
341 bitmapInfo.biYPelsPerMeter = 0;
342 bitmapInfo.biClrUsed = 0;
343 bitmapInfo.biClrImportant = 0;
346 HBITMAP winBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS, (VOID**)&bits, NULL, 0);
347 HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
348 DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_NORMAL);
349 QImage image = qt_fromWinHBITMAP(hdc, winBitmap, w, h);
351 for (
int y = 0 ; y < h && !foundAlpha ; y++) {
353 for (
int x = 0; x < w ; x++) {
354 if (
qAlpha(scanLine[x]) != 0) {
362 DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_MASK);
363 QImage mask = qt_fromWinHBITMAP(hdc, winBitmap, w, h);
365 for (
int y = 0 ; y < h ; y++){
368 for (
int x = 0; x < w ; x++){
369 if (scanlineMask &&
qRed(scanlineMask[x]) != 0)
370 scanlineImage[x] = 0;
372 scanlineImage[x] |= 0xff000000;
377 DeleteObject(iconinfo.hbmMask);
378 DeleteObject(iconinfo.hbmColor);
380 SelectObject(hdc, oldhdc);
381 DeleteObject(winBitmap);
385 #else //ifndef Q_WS_WINCE 388 HDC screenDevice = GetDC(0);
389 HDC hdc = CreateCompatibleDC(screenDevice);
390 ReleaseDC(0, screenDevice);
393 bool result = GetIconInfo(icon, &iconinfo);
395 qWarning(
"QPixmap::fromWinHICON(), failed to GetIconInfo()");
399 if (!iconinfo.xHotspot || !iconinfo.yHotspot) {
403 int result = GetObject(iconinfo.hbmColor,
sizeof(BITMAP), &bm);
404 if (!result) result = GetObject(iconinfo.hbmMask,
sizeof(BITMAP), &bm);
406 qWarning(
"QPixmap::fromWinHICON(), failed to retrieve icon size");
413 w = iconinfo.xHotspot * 2;
414 h = iconinfo.yHotspot * 2;
416 const DWORD dwImageSize = w * h * 4;
419 memset(&bmi, 0,
sizeof(bmi));
420 bmi.bmiHeader.biSize =
sizeof(BITMAPINFO);
421 bmi.bmiHeader.biWidth = w;
422 bmi.bmiHeader.biHeight = -h;
423 bmi.bmiHeader.biPlanes = 1;
424 bmi.bmiHeader.biBitCount = 32;
425 bmi.bmiHeader.biCompression = BI_RGB;
426 bmi.bmiHeader.biSizeImage = dwImageSize;
430 HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (
void**) &bits, 0, 0);
432 memset(bits, 0xff, dwImageSize);
434 qWarning(
"QPixmap::fromWinHICON(), failed to CreateDIBSection()");
438 HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
439 if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_NORMAL))
440 qWarning(
"QPixmap::fromWinHICON(), failed to DrawIcon()");
447 int bytes_per_line = w *
sizeof(
QRgb);
448 for (
int y=0; y < h; ++y) {
450 const QRgb *src = (
const QRgb *) (bits + y * bytes_per_line);
451 for (
int x=0; x < w; ++x) {
456 if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_MASK))
457 qWarning(
"QPixmap::fromWinHICON(), failed to DrawIcon()");
459 int bytes_per_line = w *
sizeof(
QRgb);
460 for (
int y=0; y < h; ++y) {
462 const QRgb *src = (
const QRgb *) (bits + y * bytes_per_line);
463 for (
int x=0; x < w; ++x) {
465 dest[x] = dest[x] |
mask;
469 SelectObject(hdc, oldhdc);
470 DeleteObject(winBitmap);
474 #endif //ifndef Q_WS_WINCE 475 #endif //ifdef Q_WS_WIN
QImage toImage() const
Converts the pixmap to a QImage.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Format
The following image formats are available in Qt.
HBitmapFormat
HBITMAP and QPixmap is performed.
QPixmap()
Constructs a null pixmap.
#define QT_END_NAMESPACE
This macro expands to.
static QPixmap fromWinHICON(HICON hicon)
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
QExplicitlySharedDataPointer< QPixmapData > data
Q_CORE_EXPORT void qFree(void *ptr)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
#define GetDIBits(a, b, c, d, e, f, g)
static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format=NoAlpha)
Win32 only: Returns a QPixmap that is equivalent to the given bitmap.
bool qt_wince_is_pocket_pc()
int bytesPerLine() const
Returns the number of bytes per image scanline.
Q_CORE_EXPORT void * qMalloc(size_t size)
int depth() const
Returns the depth of the pixmap.
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
The QBitmap class provides monochrome (1-bit depth) pixmaps.
T * data() const
Returns a pointer to the shared data object.
#define QT_BEGIN_NAMESPACE
This macro expands to.
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
#define FALSE
Synonym for false.
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
int width() const
Returns the width of the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
bool qt_wince_is_high_dpi()
HBITMAP toWinHBITMAP(HBitmapFormat format=NoAlpha) const
It is the caller's responsibility to free the HBITMAP data after use.
QBitmap mask() const
Extracts a bitmap mask from the pixmap's alpha channel.
HICON toWinHICON() const
Returns the HICON handle.
int height() const
Returns the height of the image.
QRect rect() const
Returns the pixmap's enclosing rectangle.
The QPixmap class is an off-screen image representation that can be used as a paint device...
HBITMAP qt_createIconMask(const QBitmap &bitmap)
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
void qErrnoWarning(const char *msg,...)