2008年(41)
分类: LINUX
2008-11-19 10:50:22
qt半透明
QFrame *frame = new QFrame();
QPixmap grabPixmap = QPixmap::grabWindow( frame->winId(), 20, 0, 100, 100 );
frame->setGeometry( 20, 20, 100, 100 );
frame->hide();
QPixmap pixmap = Resource::loadPixmap( "qpelogo" );
QImage image = pixmap.convertToImage();
//image.convertDepth( 32 );
image.setAlphaBuffer( true );
QImage bgImage = grabPixmap.convertToImage();
//bgImage.convertDepth( 32 );
bgImage.setAlphaBuffer( true );
double k = 0.5;
QRgb *rgbpos1 = image.colorTable();
QRgb *rgbpos2 = bgImage.colorTable();
for( int y = 0; y < 80; y++ )
for( int x = 0; x < 80; x++ )
{
#if 1
uint rgb1 = image.pixel( x, y );
uint rgb2 = bgImage.pixel( x, y );
unsigned int red = qRed(rgb1);
unsigned int green = qGreen(rgb1);
unsigned int blue = qBlue(rgb1);
unsigned int bgred = qRed(rgb2);
unsigned int bggreen = qGreen(rgb2);
unsigned int bgblue = qBlue(rgb2);
red = k * red + ( 1 - k ) * bgred;
green = k * green + ( 1 - k ) * bggreen;
blue = k * blue + ( 1 - k ) * bgblue;
//red = red << 4;
//green = green << 4;
//blue = blue << 4;
#endif
//color = QColor( red, green, blue );
//unsigned int myrgb = color.rgb();
//image.setPixel( x, y, myrgb );
uint *p = (uint *)image.scanLine(y) + x;
*p = qRgb( red, green, blue );
}
qWarning("%d %d", image.depth(), bgImage.depth());
grabPixmap.convertFromImage( image );
frame->setBackgroundPixmap( grabPixmap );
frame->show();
#endif
引自: http://spaces.baidu.com/sszllx/blog/item/ab833a59ea98622f2934f001.html