QImage fragment( "test.png" ); int w = fragment.width(); int h = fragment.height(); for( int x = 0; x < w; ++x ) for( int y = 0; y < h; ++y ){ QRgb rgb = fragment.pixel( x, y ); int red = qRed( rgb ); int green = qGreen( rgb ); int blue = qBlue( rgb ); QColor color( red, green, blue ); if( red == 200 && green == 204 && blue == 200 ){ color.setAlpha( 100 ); } }
QImage fragment( exampleObject->size(), QImage::Format_ARGB32 ); fragment = exampleObject->copy( 30, 277, 110, 102 ); QPixmap alphaPixmap( QSize( fragment.size() ) ); alphaPixmap.fill( QColor( 200, 204, 200 ) ); QPixmap fragmentAlpha( fragment ); fragmentAlpha.setAlphaChannel( alphaPixmap ); fragmentAlpha.save( "alfa.png", "PNG", -1 );
QImage fragment( exampleObject->size(), QImage::Format_ARGB32 ); fragment = exampleObject->copy( 30, 277, 110, 102 ); //Подключаем альфа канал QPixmap alpha( QSize( fragment.size() ) ); alpha.fill( QColor( 255,255,255 ) ); fragment.setAlphaChannel( alpha ); int w = fragment.width(); int h = fragment.height(); for( int y = 0; y < h; ++y ) for( int x = 0; x < w; ++x ){ QRgb rgb = fragment.pixel( x, y ); int red = qRed( rgb ); int green = qGreen( rgb ); int blue = qBlue( rgb ); //в if прописываем цвет фона if( red == 200 && green == 204 && blue == 200 ){ fragment.setPixel( x, y, qRgba( 255, 255, 255, 0 ) ); } else { fragment.setPixel( x, y, qRgba( red, green, blue, 255 ) ); } }
QPixmap alfaPixmap;alfaPixmap=Pixmap->createMaskFromColor(QColor(0,255,255),Qt::MaskOutColor);Pixmap->setAlphaChannel(alfaPixmap);