Results 1 to 2 of 2

Thread: QImage internal error

  1. #1
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    15
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QImage internal error

    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'
    Happiness depends on being self-sufficient, and a master of mental attitude, self-sufficiency is achieved by living a life of Virtue - Cynics

  2. #2
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    15
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage internal error

    seems that every declaration of a QImage leads to this error, no solutions at the moment
    Happiness depends on being self-sufficient, and a master of mental attitude, self-sufficiency is achieved by living a life of Virtue - Cynics

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  5. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.