Results 1 to 4 of 4

Thread: Port MFC BITMAP Code to Qt?

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Port MFC BITMAP Code to Qt?

    In MFC I used this (ugly) code to display data in bmp Format. Now I have the same Data structure, but want to display it on a QImage. But how do I port this code? (using opensource 4.4 edition)

    Qt Code:
    1. void CGraphCtrl::OnPaint()
    2. {
    3. CPaintDC dc(this); // device context for painting
    4.  
    5. if (PixelNumber.x == 0)
    6. return;
    7.  
    8. //First step: Create BITMAP Header info:
    9. BITMAPINFOHEADER bitmapInfo;
    10. ::ZeroMemory(&bitmapInfo,sizeof(BITMAPINFOHEADER));
    11. bitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
    12. bitmapInfo.biWidth = PixelNumber.width();/*enter Width*/
    13. bitmapInfo.biHeight = -PixelNumber.height();/*enter Height*/
    14. bitmapInfo.biPlanes = 1;
    15. bitmapInfo.biBitCount = m_DibColorDepth;
    16. bitmapInfo.biCompression = BI_RGB; //RGB
    17. //bitmapInfo.biSizeImage = bitmapInfo.biWidth*bitmapInfo.biHeight*bitmapInfo.biBitCount/8;
    18. bitmapInfo.biSizeImage = m_DibSize;;
    19.  
    20. SetDIBitsToDevice(
    21. dc,
    22. 0, //dx
    23. 0, //dy
    24. PixelNumber.x, // width
    25. PixelNumber.y, // height
    26. 0,
    27. 0,
    28. 0,
    29. PixelNumber.y,
    30. pDIBData,
    31. (LPBITMAPINFO)&bitmapInfo,
    32. DIB_RGB_COLORS);
    33.  
    34. return;
    35. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Port MFC BITMAP Code to Qt?

    I guess u dont have to care about the bmp format. Qt does it for u.
    You can simply read .bmp into QImage, or save as - QImage::save("bmpPic.bmp") ;
    From the docs -
    bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const
    Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Port MFC BITMAP Code to Qt?

    Quote Originally Posted by aamer4yu View Post
    I guess u dont have to care about the bmp format. Qt does it for u.
    You can simply read .bmp into QImage, or save as - QImage::save("bmpPic.bmp") ;
    From the docs -
    Probably I did not deliver enough details, since your advice has nothing to do with my problem. I want to plot (not save nor load from disk) data which is placed inside a char * Array (here called pDIBData) to a QImage.

    In MFC such an Array is converted in the way shown to an Bitmap (*.bmp format) which is then delivered to a function SetDIBitsToDevice which maps the Bitmap to a Pixmap which is printed on the screen.

    So in other words: How do I convert DIB char * Data to a QImage, which I can easily print to the screen?

    Matthias

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Port MFC BITMAP Code to Qt?

    ok,, sorry i didnt get u..
    Did u have a look at QImage::fromData ??
    May be thats what u are looking for

Similar Threads

  1. Replies: 6
    Last Post: 18th April 2007, 16:04
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 14:15
  3. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 22:41
  4. Mac Port of Windows code
    By Nemo in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2006, 08:37

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
  •  
Qt is a trademark of The Qt Company.