Chinaunix首页 | 论坛 | 博客
  • 博客访问: 184839
  • 博文数量: 41
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 600
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-23 21:42
文章分类

全部博文(41)

文章存档

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

阅读(2245) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~