//when loading an image
scene->clear();
scene->addItem( image );
...
//when displaying the image (and processing it)
if(imagePix == NULL)
return;
//if(mask1 != NULL){
qDebug()<<"here0";
scene->removeItem(mask1);
//delete mask1;
//}
qDebug()<<"here1";
int w = imagePix->width();
int h = imagePix->height();
painter.setPen( Qt::black );
painter.setBrush( Qt::black );
painter.drawRect(imagePix->rect());
painter.end();
mask1Pix->fill(qRgb(255,255,255));
ui->bar->setVisible(true);
ui->bar->setValue(0);
int pix = w*h;
QImage src
= imagePix
->toImage
();
//here paint what areas to reveal--------------------------------------------------
for(int i=0; i<w; i++){
for(int j=0; j<h; j++){
QRgb p = src.pixel(i,j);
if( qRed(p) - qBlue(p) - qGreen(p) >= 10){
mask1Pix->setPixel( i,j, qRgb(0,0,0) ); //where red - will be transparent
}
}
ui->bar->setValue(((i+1)*h*100)/pix);
}
//--------------------------------------------------------------------------------
ui->bar->setValue(0);
ui->bar->setVisible(false);
temp
->setAlphaChannel
( QPixmap::fromImage( *mask1Pix
) );
mask1->setZValue(2);
mask1->setOpacity(0.9f);
scene->addItem(mask1);
qDebug() << imagePix << mask1Pix << "\n"<< image << mask1;
delete temp;
//when loading an image
imagePix = new QPixmap(fileName);
scene->clear();
image = new QGraphicsPixmapItem( *imagePix );
scene->addItem( image );
...
//when displaying the image (and processing it)
if(imagePix == NULL)
return;
//if(mask1 != NULL){
qDebug()<<"here0";
scene->removeItem(mask1);
//delete mask1;
//}
qDebug()<<"here1";
int w = imagePix->width();
int h = imagePix->height();
QPixmap *temp = new QPixmap( w,h );
QPainter painter(temp);
painter.setPen( Qt::black );
painter.setBrush( Qt::black );
painter.drawRect(imagePix->rect());
painter.end();
mask1Pix = new QImage(w,h, QImage::Format_RGB888);
mask1Pix->fill(qRgb(255,255,255));
ui->bar->setVisible(true);
ui->bar->setValue(0);
int pix = w*h;
QImage src = imagePix->toImage();
//here paint what areas to reveal--------------------------------------------------
for(int i=0; i<w; i++){
for(int j=0; j<h; j++){
QRgb p = src.pixel(i,j);
if( qRed(p) - qBlue(p) - qGreen(p) >= 10){
mask1Pix->setPixel( i,j, qRgb(0,0,0) ); //where red - will be transparent
}
}
ui->bar->setValue(((i+1)*h*100)/pix);
}
//--------------------------------------------------------------------------------
ui->bar->setValue(0);
ui->bar->setVisible(false);
temp->setAlphaChannel( QPixmap::fromImage( *mask1Pix ) );
mask1 = new QGraphicsPixmapItem( *temp );
mask1->setZValue(2);
mask1->setOpacity(0.9f);
scene->addItem(mask1);
qDebug() << imagePix << mask1Pix << "\n"<< image << mask1;
delete temp;
To copy to clipboard, switch view to plain text mode
Bookmarks