QImage colorTable???
Verfasst: 13. August 2012 13:40
Hallo, ich versuche gerade ein .png per QFileDialog zu öffnen. Klappt sowohl für .txt, als auch für .png! Leider bleibt mein Bild in meinem QLabel farblos, also in Graustufen. Habe jetzt nach mehrfacher Erörterung der Docu und allem was Google hergibt versucht einen ColorTable zu bilden, kriegs aber iwie nicht hin. Also mir ist irgendwie klar, dass wenn ich in meiner Schleife sage qRgb (i,i,i), dass das Bild wohl grau wird. Wie mache ich es anders? Drei Schleifen mit Variablen i, j, k für die jeweiligen RGB Werte??
Wäre super wenn jemand helfen könnte, weil ich da jetzt schon Tage vorsitze und nicht mehr weiter weiß.... :-/ ....Danke schon mal. .....ach ja.....nutze QT 4 auf Windows
void MyClass::open()
{
QString filename = QFileDialog::getOpenFileName(this,tr("Load File"),"",tr("Text Files (*.txt);;Images (*.png *.jpg)"));
if (filename != "") {
/*QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;}
QString contents = file.readAll().constData();
ui.Textfeld -> setPlainText(contents);
file.close();}*/
QImage image(filename);
image = image.convertToFormat(QImage::Format_Indexed8); //shows the image in gray
/*image = QImage(600, 453, QImage::Format_Indexed8);*/ // shows black and white stripes (why?)
QVector<QRgb> table(256);
for(int i = 0; i < table.size(); i++)
{table = qRgb ( i,i,i );}
image.setColorTable(table);
/*QRgb i;
for ( int i=0; i<256; i++ ) //build color Table
image.setColor(i,qRgb(i,i,i));*/
//image.fill(qRgb(255,255,255));
//image.setColor( 19, qRgb(255,255,0) );
//(image.scanLine(y) + x) = 19;
/*QPixmap pixmap;
pixmap = pixmap.fromImage(image);*/
ui.Display->setPixmap(QPixmap::fromImage(image));}
}
Wäre super wenn jemand helfen könnte, weil ich da jetzt schon Tage vorsitze und nicht mehr weiter weiß.... :-/ ....Danke schon mal. .....ach ja.....nutze QT 4 auf Windows
void MyClass::open()
{
QString filename = QFileDialog::getOpenFileName(this,tr("Load File"),"",tr("Text Files (*.txt);;Images (*.png *.jpg)"));
if (filename != "") {
/*QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;}
QString contents = file.readAll().constData();
ui.Textfeld -> setPlainText(contents);
file.close();}*/
QImage image(filename);
image = image.convertToFormat(QImage::Format_Indexed8); //shows the image in gray
/*image = QImage(600, 453, QImage::Format_Indexed8);*/ // shows black and white stripes (why?)
QVector<QRgb> table(256);
for(int i = 0; i < table.size(); i++)
{table = qRgb ( i,i,i );}
image.setColorTable(table);
/*QRgb i;
for ( int i=0; i<256; i++ ) //build color Table
image.setColor(i,qRgb(i,i,i));*/
//image.fill(qRgb(255,255,255));
//image.setColor( 19, qRgb(255,255,0) );
//(image.scanLine(y) + x) = 19;
/*QPixmap pixmap;
pixmap = pixmap.fromImage(image);*/
ui.Display->setPixmap(QPixmap::fromImage(image));}
}