ich habe da mal ein tool geschrieben, was das mit qimage macht. hoffe das hilft dir.
Code: Alles auswählen
#include "rgbscanner.h"
RGBScanner::RGBScanner(QWidget *parent)
: QWidget(parent)
{
scanPos = 0;
scanMode = 1;
scanTimer = new QTimer();
scanImg.load("Scan.png");
scanTimer->start(0);
connect(scanTimer, SIGNAL(timeout()), this, SLOT(repaint()));
iWidth = scanImg.width();
setFixedSize(scanImg.width(), scanImg.height());
}
void RGBScanner::ScanImage()
{
}
void RGBScanner::paintEvent(QPaintEvent *e)
{
if(scanMode == 6)
scanMode = 1;
if(scanPos == scanImg.height()+1)
{
scanPos = 0;
++scanMode;
}
switch(scanMode)
{
case 1:
scanTimer->start(10);
dPix = QPixmap(scanImg.width(), scanImg.height());
dPix.fill();
Stage1();
break;
case 2:
dPix = QPixmap(scanImg.width(), scanImg.height());
dPix.fill();
Stage2();
break;
case 3:
dPix = QPixmap(scanImg.width(), scanImg.height());
dPix.fill();
Stage3();
break;
case 4:
dPix = QPixmap(scanImg.width(), scanImg.height());
dPix.fill();
Stage4();
break;
case 5:
scanTimer->start(30);
Stage5();
break;
}
QPainter p(this);
p.fillRect(rect(), dPix);
p.end();
++scanPos;
}
void RGBScanner::Stage1()
{
QPainter p(&dPix);
QImage sImg = scanImg;
for(int i = 0; i < scanPos; ++i)
for(int j = 0; j < iWidth; ++j)
{
QRgb rgb = qRgba(qRed(scanImg.pixel(j,i)),0,0,qAlpha(scanImg.pixel(j,i)));
sImg.setPixel(j,i, rgb);
}
p.drawPixmap(QRect(0, 0, iWidth, scanPos),
QPixmap::fromImage(sImg),
QRect(0, 0, iWidth, scanPos));
for(int j = 0; j < iWidth; ++j)
{
QColor fc = QColor(qRed(scanImg.pixel(j,scanPos)), 0, 0,qAlpha(scanImg.pixel(j,scanPos)));
p.fillRect(j,scanPos,10,10,fc);
}
p.setPen(QPen(Qt::green, 1));
p.drawLine(QPoint(0, scanPos+9), QPoint(iWidth, scanPos+9));
p.drawLine(QPoint(0, scanPos+10), QPoint(iWidth, scanPos+10));
p.end();
}
void RGBScanner::Stage2()
{
QPainter p(&dPix);
QImage sImg = scanImg;
for(int i = 0; i < scanPos; ++i)
for(int j = 0; j < iWidth; ++j)
{
QRgb rgb = qRgba(0,qGreen(scanImg.pixel(j,i)),0,qAlpha(scanImg.pixel(j,i)));
sImg.setPixel(j,i, rgb);
}
p.drawPixmap(QRect(0, 0, iWidth, scanPos),
QPixmap::fromImage(sImg),
QRect(0, 0, iWidth, scanPos));
for(int j = 0; j < iWidth; ++j)
{
QColor fc = QColor(0, qGreen(scanImg.pixel(j,scanPos)), 0,qAlpha(scanImg.pixel(j,scanPos)));
p.fillRect(j,scanPos,10,10,fc);
}
p.setPen(QPen(Qt::red, 1));
p.drawLine(QPoint(0, scanPos+9), QPoint(iWidth, scanPos+9));
p.drawLine(QPoint(0, scanPos+10), QPoint(iWidth, scanPos+10));
p.end();
}
void RGBScanner::Stage3()
{
QPainter p(&dPix);
QImage sImg = scanImg;
for(int i = 0; i < scanPos; ++i)
for(int j = 0; j < iWidth; ++j)
{
QRgb rgb = qRgba(0,0,qBlue(scanImg.pixel(j,i)),qAlpha(scanImg.pixel(j,i)));
sImg.setPixel(j,i, rgb);
}
p.drawPixmap(QRect(0, 0, iWidth, scanPos),
QPixmap::fromImage(sImg),
QRect(0, 0, iWidth, scanPos));
for(int j = 0; j < iWidth; ++j)
{
QColor fc = QColor(0,
0,
qBlue(scanImg.pixel(j,scanPos)),qAlpha(scanImg.pixel(j,scanPos)));
p.fillRect(j,scanPos,10,10,fc);
}
p.setPen(QPen(Qt::yellow, 1));
p.drawLine(QPoint(0, scanPos+9), QPoint(iWidth, scanPos+9));
p.drawLine(QPoint(0, scanPos+10), QPoint(iWidth, scanPos+10));
p.end();
}
void RGBScanner::Stage4()
{
QPainter p(&dPix);
p.drawPixmap(QRect(0, 0, iWidth, scanPos),
QPixmap::fromImage(scanImg.rgbSwapped()),
QRect(0, 0, iWidth, scanPos));
for(int j = 0; j < iWidth; ++j)
{
QColor fc = QColor(qBlue(scanImg.pixel(j,scanPos)),
qGreen(scanImg.pixel(j,scanPos)),
qRed(scanImg.pixel(j,scanPos)),qAlpha(scanImg.pixel(j,scanPos)));
p.fillRect(j,scanPos,10,10,fc);
}
p.setPen(QPen(Qt::green, 1));
p.drawLine(QPoint(0, scanPos+9), QPoint(iWidth, scanPos+9));
p.setPen(QPen(Qt::red, 1));
p.drawLine(QPoint(0, scanPos+10), QPoint(iWidth, scanPos+10));
p.setPen(QPen(Qt::yellow, 1));
p.drawLine(QPoint(0, scanPos+11), QPoint(iWidth, scanPos+11));
p.end();
}
void RGBScanner::Stage5()
{
QPainter p(&dPix);
int hor = (scanImg.height()/iWidth)+1;
p.fillRect(rect(), QPixmap::fromImage(scanImg));
p.setPen(QPen(Qt::green, 1));
p.drawLine(QPointF(scanPos, 0), QPointF(scanPos, scanImg.height()));
p.setPen(QPen(Qt::red, 1));
p.drawLine(QPointF(iWidth-scanPos, 0), QPointF(iWidth-scanPos, scanImg.height()));
p.setPen(QPen(Qt::yellow, 1));
p.drawLine(QPointF(0, scanPos*hor), QPointF(iWidth, scanPos*hor));
p.setPen(QPen(Qt::blue, 1));
p.drawLine(QPointF(0, scanImg.height()-scanPos*hor), QPointF(iWidth, scanImg.height()-scanPos*hor));
p.end();
}