PDA

View Full Version : QImage internal error



GiuseppeBonfa
4th August 2009, 08:03
Hi,

I'm coding a processviewer in windows, and due the necessity to convert HICON to Pixmap I've used a function of Qt sources, convertHIconToPixmap the problem is that application crashes, by debugging I've discovered that a QImage img presents a problem,

img <internal error> from Debugger Prompt

here the function



QPixmap ProcessView::ConvertHTP(const HICON icon) const
{
bool foundAlpha = false;
HDC screenDevice = qt_win_display_dc();
HDC hdc = CreateCompatibleDC(screenDevice);


ICONINFO iconinfo;
GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center

BITMAPINFOHEADER bitmapInfo;
bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo.biWidth = iconinfo.xHotspot * 2;
bitmapInfo.biHeight = iconinfo.yHotspot * 2;
bitmapInfo.biPlanes = 1;
bitmapInfo.biBitCount = 32;
bitmapInfo.biCompression = BI_RGB;
bitmapInfo.biSizeImage = 0;
bitmapInfo.biXPelsPerMeter = 0;
bitmapInfo.biYPelsPerMeter = 0;
bitmapInfo.biClrUsed = 0;
bitmapInfo.biClrImportant = 0;
DWORD* bits;

HBITMAP winBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS, (VOID**)&bits, NULL, 0);
HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_NORMAL);

QPixmap::HBitmapFormat alphaType = QPixmap::PremultipliedAlpha;
QPixmap iconpixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
QImage img = iconpixmap.toImage(); // PROBLEM HERE

for (int y = 0 ; y < iconpixmap.height() && !foundAlpha ; y++) {
QRgb *scanLine= reinterpret_cast<QRgb *>(img.scanLine(y));
for (int x = 0; x < img.width() ; x++) {
if (qAlpha(scanLine[x]) != 0) {
foundAlpha = true;
break;
}
}
}

if (!foundAlpha) {
//If no alpha was found, we use the mask to set alpha values
DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_MASK);
QPixmap maskPixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
QImage mask = maskPixmap.toImage();

for (int y = 0 ; y< iconpixmap.height() ; y++){
QRgb *scanlineImage = reinterpret_cast<QRgb *>(img.scanLine(y));
QRgb *scanlineMask = reinterpret_cast<QRgb *>(mask.scanLine(y));
for (int x = 0; x < img.width() ; x++){
if (qRed(scanlineMask[x]) != 0)
scanlineImage[x] = 0; //mask out this pixel
else
scanlineImage[x] |= 0xff000000; // set the alpha channel to 255
}
}
}

//dispose resources created by iconinfo call
DeleteObject(iconinfo.hbmMask);
DeleteObject(iconinfo.hbmColor);

SelectObject(hdc, oldhdc); //restore state
DeleteObject(winBitmap);
DeleteDC(hdc);
return QPixmap::fromImage(img);
}


how can be solved QImage img <internal error> ? thanks

Regards,
Giuseppe Bonfa'

GiuseppeBonfa
4th August 2009, 15:12
seems that every declaration of a QImage leads to this error, no solutions at the moment