Results 1 to 6 of 6

Thread: Creating images from sets of data.

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Creating images from sets of data.

    Hi,

    I am looking for a method to port MFC code to QT;

    This is the MFC code:
    Qt Code:
    1. short int tab = { 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF };
    2. CBitmap* bitmap;
    3. bitmap -> CreateBitmap(8, 8, 1, 1, tab);
    To copy to clipboard, switch view to plain text mode 

    I need to create a QBrush from that bitmap.

    Thanks for help.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating images from sets of data.


  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating images from sets of data.

    Thanks.

    Can we cast short int -> uchar* without any error?
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Creating images from sets of data.

    uchar is 8b long whereas short int is 16b on 32b machines. Might be different on others, but I suggest you try and see for yourself.

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating images from sets of data.

    Ok. Thanks all for help.
    Here's the final code I have:
    Qt Code:
    1. /*! Some data*/
    2. QByteArray array;
    3. array.resize(18);
    4. array[0] =0x0089;
    5. array[1] =0x0044;
    6. array[2] =0x0010;
    7. array[3] =0x0022;
    8. array[4] =0x0094;
    9. array[5] =0x0002;
    10. array[6] =0x0068;
    11. array[7] =0x0001;
    12.  
    13. QImage image(QSize(8,8),QImage::Format_MonoLSB);
    14. image.loadFromData(array);
    To copy to clipboard, switch view to plain text mode 

    Now, though, I would like to convert this image: change black pixels -> transparent background, change white-like element to the selected colour.
    If you have any idea I would appreciate your help.

    Kacper
    Attached Images Attached Images
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating images from sets of data.

    Got the answer:
    Qt Code:
    1. qDebug()<<image.colorTable().size();/*!< "2" -> white & black */
    2. image.setColor(0,Qt::transparent);/*!< Black -> transparent*/
    3. image.setColor(1,qRgb(255,0,0));/*!< White-> red*/
    To copy to clipboard, switch view to plain text mode 

    Sorry for bothering you.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. QGLWidget problem
    By MarkoSan in forum Qt Programming
    Replies: 33
    Last Post: 8th December 2007, 15:50
  2. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00
  3. Replies: 3
    Last Post: 17th May 2007, 13:50
  4. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 15:21
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.