Results 1 to 20 of 21

Thread: Problems working with 8bpp and 24bpp images

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Thumbs up Problems working with 8bpp and 24bpp images

    Hi all, I am programming a simple photo editor program in Qt4.1 with winXp. Well, one of the utilities of the editor is to paint with a given color a selected rectangular area of the image. The code to paint this area is as follows:

    Qt Code:
    1. void FotoEditorFotos::paintRect(const QColor &color, const QRect &rectAPintar)
    2. {
    3. int xMin = rectAPintar.x();
    4. int xMax = xMin + rectAPintar.width() - 1;
    5. int yMin = rectAPintar.y();
    6. int yMax = yMin + rectAPintar.height() - 1;
    7.  
    8. if ( !imatge.valid(xMin, yMin) || !imatge.valid(xMax, yMax)) return;
    9.  
    10. QRgb *pixelsLiniaFoto;
    11. QRgb valorColor = color.rgb();
    12.  
    13. for (int j = yMin; j <= yMax; j++)
    14. {
    15. pixelsLiniaFoto = ((QRgb *) imatge.scanLine(j)) + xMin;
    16.  
    17. for (int i = xMin; i <= xMax; i++)
    18. {
    19. *pixelsLiniaFoto = valorColor;
    20. pixelsLiniaFoto++;
    21. }
    22. }
    23.  
    24. update();
    25. }
    To copy to clipboard, switch view to plain text mode 

    The photo (imatge) is part of the class. Well the problem with the code above is that only works with images with 24 bits/pixel, but on the images with 8bpp it give me invalid results. The problem, I guess, is the cast to QRgb*. Anybody knows how to solve it? Thanks.
    Last edited by SkripT; 13th February 2006 at 14:33.

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.