I am not sure wether I understood your request the right way. I am assuming that you want to convert all black pixels to full transparency and all other pixels to red.
The first point is your loop which is not correctly initialized. Even if you initialized x and y outside the loop, latest when scanning the second column your variable y will be out of range, so the inner loop will be performed only once.
Your loop should look like
for ( x = 0; x < secondaryImage.width(); ++x )
{
for ( y = 0; y < secondaryImage.height(); ++y )
{
if ( secondaryImage.pixel( x, y ) == Qt::black )
secondaryImage.
setPixel( x, y,
QColor( 0,
0,
0,
0 ));
// fully transparency, color doesn´t matter else
secondaryImage.setPixel( x, y, Qt::red );
}
}
for ( x = 0; x < secondaryImage.width(); ++x )
{
for ( y = 0; y < secondaryImage.height(); ++y )
{
if ( secondaryImage.pixel( x, y ) == Qt::black )
secondaryImage.setPixel( x, y, QColor( 0, 0, 0, 0 )); // fully transparency, color doesn´t matter
else
secondaryImage.setPixel( x, y, Qt::red );
}
}
To copy to clipboard, switch view to plain text mode
I did not test the code!
Bookmarks