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:
void FotoEditorFotos
::paintRect(const QColor &color,
const QRect &rectAPintar
) {
int xMin = rectAPintar.x();
int xMax = xMin + rectAPintar.width() - 1;
int yMin = rectAPintar.y();
int yMax = yMin + rectAPintar.height() - 1;
if ( !imatge.valid(xMin, yMin) || !imatge.valid(xMax, yMax)) return;
QRgb *pixelsLiniaFoto;
QRgb valorColor = color.rgb();
for (int j = yMin; j <= yMax; j++)
{
pixelsLiniaFoto = ((QRgb *) imatge.scanLine(j)) + xMin;
for (int i = xMin; i <= xMax; i++)
{
*pixelsLiniaFoto = valorColor;
pixelsLiniaFoto++;
}
}
update();
}
void FotoEditorFotos::paintRect(const QColor &color, const QRect &rectAPintar)
{
int xMin = rectAPintar.x();
int xMax = xMin + rectAPintar.width() - 1;
int yMin = rectAPintar.y();
int yMax = yMin + rectAPintar.height() - 1;
if ( !imatge.valid(xMin, yMin) || !imatge.valid(xMax, yMax)) return;
QRgb *pixelsLiniaFoto;
QRgb valorColor = color.rgb();
for (int j = yMin; j <= yMax; j++)
{
pixelsLiniaFoto = ((QRgb *) imatge.scanLine(j)) + xMin;
for (int i = xMin; i <= xMax; i++)
{
*pixelsLiniaFoto = valorColor;
pixelsLiniaFoto++;
}
}
update();
}
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.
Bookmarks