Results 1 to 6 of 6

Thread: Accessing a QBitmap's underlying bits

  1. #1
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Accessing a QBitmap's underlying bits

    Hello,

    I'm writing an application that must print arbitrary images onto a monochrome receipt printer, that behaves like an old dot matrix printer (I think). I think that I can use a QBitmap to do so - I'd certainly need to use some form of dithering, because I'm converting full colour images into greyscale bitmaps. I need to get 8 pixels at a time, in the form of a single byte (1 bit per pixel), and then feed them to the printer in what is perhaps a slightly unusual order.

    So, I'd instantiate a QBitmap, and use its toData() method to create a bitmap from a PNG file buffer, at the same time resizing it to conform it to the correct resolution, and then somehow retrieve those raw bits from the QBitmap.

    Is this general approach sound? How can I retrieve those raw bits?

    Regards,
    Sternocera

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Accessing a QBitmap's underlying bits

    What you want is QImage not QBitmap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Accessing a QBitmap's underlying bits

    But how can I conform the image to the 1-bit palette, using a dithering algorithm to preserve details? I've looked at QImage, and I see that it's the only class Qt provides to access underlying bits.

    Should I instantiate a QBitmap, load a PNG image into it and then convert it to a QImage in order to get the image as a dithered?

    In any case, if I access raw bits using any of QImage's methods, I'm unsure if can get them as an actual bitmap - i.e. one bit per pixel, rather than some other representation that represents a greater color depth, or transparency or whatever else, where each pixel takes up more than a bit.

    What approach is suggested?

    Regards,
    Sternocera

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Accessing a QBitmap's underlying bits

    Use QImage with Format_Mono. And please read the docs about it and different colour formats. This will answer your questions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Accessing a QBitmap's underlying bits

    Alright, I see that by specifying the Format as QImage::Format_Mono the image is stored using 1-bit per pixel. But, shouldn't I somehow dither the image? The image will be taken from a png image. How will QImage conform the image to QImage::Format_Mono? Will it use dithering? The documentation is not clear on that.

    I don't have a compiler in front of me at the moment to test it myself.

    Regards,
    Sternocera

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Accessing a QBitmap's underlying bits

    The documentation is very clear about it. See Qt::ImageConversionFlag.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    sternocera (6th April 2009)

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.