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

Qt Code:
  1. QPixmap ProcessView::ConvertHTP(const HICON icon) const
  2. {
  3. bool foundAlpha = false;
  4. HDC screenDevice = qt_win_display_dc();
  5. HDC hdc = CreateCompatibleDC(screenDevice);
  6.  
  7.  
  8. ICONINFO iconinfo;
  9. GetIconInfo(icon, &iconinfo); //x and y Hotspot describes the icon center
  10.  
  11. BITMAPINFOHEADER bitmapInfo;
  12. bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
  13. bitmapInfo.biWidth = iconinfo.xHotspot * 2;
  14. bitmapInfo.biHeight = iconinfo.yHotspot * 2;
  15. bitmapInfo.biPlanes = 1;
  16. bitmapInfo.biBitCount = 32;
  17. bitmapInfo.biCompression = BI_RGB;
  18. bitmapInfo.biSizeImage = 0;
  19. bitmapInfo.biXPelsPerMeter = 0;
  20. bitmapInfo.biYPelsPerMeter = 0;
  21. bitmapInfo.biClrUsed = 0;
  22. bitmapInfo.biClrImportant = 0;
  23. DWORD* bits;
  24.  
  25. HBITMAP winBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bitmapInfo, DIB_RGB_COLORS, (VOID**)&bits, NULL, 0);
  26. HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
  27. DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_NORMAL);
  28.  
  29. QPixmap::HBitmapFormat alphaType = QPixmap::PremultipliedAlpha;
  30. QPixmap iconpixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
  31. [B]QImage img = iconpixmap.toImage();[/B] // PROBLEM HERE
  32.  
  33. for (int y = 0 ; y < iconpixmap.height() && !foundAlpha ; y++) {
  34. QRgb *scanLine= reinterpret_cast<QRgb *>(img.scanLine(y));
  35. for (int x = 0; x < img.width() ; x++) {
  36. if (qAlpha(scanLine[x]) != 0) {
  37. foundAlpha = true;
  38. break;
  39. }
  40. }
  41. }
  42.  
  43. if (!foundAlpha) {
  44. //If no alpha was found, we use the mask to set alpha values
  45. DrawIconEx( hdc, 0, 0, icon, iconinfo.xHotspot * 2, iconinfo.yHotspot * 2, 0, 0, DI_MASK);
  46. QPixmap maskPixmap = QPixmap::fromWinHBITMAP(winBitmap, alphaType);
  47. QImage mask = maskPixmap.toImage();
  48.  
  49. for (int y = 0 ; y< iconpixmap.height() ; y++){
  50. QRgb *scanlineImage = reinterpret_cast<QRgb *>(img.scanLine(y));
  51. QRgb *scanlineMask = reinterpret_cast<QRgb *>(mask.scanLine(y));
  52. for (int x = 0; x < img.width() ; x++){
  53. if (qRed(scanlineMask[x]) != 0)
  54. scanlineImage[x] = 0; //mask out this pixel
  55. else
  56. scanlineImage[x] |= 0xff000000; // set the alpha channel to 255
  57. }
  58. }
  59. }
  60.  
  61. //dispose resources created by iconinfo call
  62. DeleteObject(iconinfo.hbmMask);
  63. DeleteObject(iconinfo.hbmColor);
  64.  
  65. SelectObject(hdc, oldhdc); //restore state
  66. DeleteObject(winBitmap);
  67. DeleteDC(hdc);
  68. return QPixmap::fromImage(img);
  69. }
To copy to clipboard, switch view to plain text mode 

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

Regards,
Giuseppe Bonfa'