Seite 1 von 1

Kein passender Konstruktor für QImage

Verfasst: Mittwoch 28. September 2011, 19:01
von antimatter
Hallo,

ich möchte gerne meine 8-Bit Graufstufenbilder (TIFF-Format) als QImage öffnen und dabei gleich als Format QImage.Format_RGB16. Denn mit

Code: Alles auswählen

QImage('bild.tif')
wird das TIF automatisch als Format_Indexed8 geöffnet und da kann ich keinen QPainter benutzen, ohne es vorher zu konvertieren. Daher benutze ich doch gleich:

Code: Alles auswählen

QImage('bild.tif', QImage.Format_RGB16)
Das Problem dabei ist aber folgendes:

Code: Alles auswählen

TypeError: arguments did not match any overloaded call:
  QImage(): too many arguments
  QImage(QSize, QImage.Format): argument 1 has unexpected type 'str'
  QImage(int, int, QImage.Format): argument 1 has unexpected type 'str'
  QImage(str, int, int, QImage.Format): not enough arguments
  QImage(sip.voidptr, int, int, QImage.Format): argument 1 has unexpected type 'str'
  QImage(str, int, int, int, QImage.Format): not enough arguments
  QImage(sip.voidptr, int, int, int, QImage.Format): argument 1 has unexpected type 'str'
  QImage(list-of-str): argument 1 has unexpected type 'str'
  QImage(QString, str format=None): argument 2 has unexpected type 'Format'
  QImage(QImage): argument 1 has unexpected type 'str'
  QImage(QVariant): too many arguments
Weiß jemand, was das bedeuten soll? Laut riverbankcomputing.co.uk ist format einer der Werte aus dem Format-enum. Ich hätte gemeint, der dritte Konstruktor von unten würde meinen Parametern entsprechen. Aber anscheinend ist dem nicht so.
Was bedeutet eigentlich dieser Zusatz "str" vor Format? String? Wie passt das mit dem Format-Enum zusammen, das nur Integers liefert? Wenn ich direkt die entsprechende Zahl hinschreibe, geht's auch nicht.

Viele Grüße
antimatter

Re: Kein passender Konstruktor für QImage

Verfasst: Mittwoch 28. September 2011, 19:45
von deets
Wie immer bei Qt lohnt sich der Blick in die Doku:

http://doc.qt.nokia.com/4.7/qimage.html#QImage-10

Und da ist es schlicht so, dass dein Wunsch nicht erfuellt wird - das format bezieht sich nicht auf die interne Repraesentation, sondern auf das Datei-Format.

Re: Kein passender Konstruktor für QImage

Verfasst: Mittwoch 28. September 2011, 21:22
von antimatter
Ach, das Dateiformat ist das. Alles klar, ungenau gelesen. Vielen Dank.

Wo wir gerade dabei sind: es funktioniert auch ohne Verwendung des format-Parameters nicht. Wenn ich versuche, das Bild mit...

Code: Alles auswählen

img = QImage('bild.tif')
... zu öffnen, dann ist img.isNull() == True. Format, Breite und Höhe steht auf 0.

Das komische daran ist, dass ich in einem anderen Programm das gleiche Bild mit demselben Befehl öffnen kann! Aber hier funktioniert das nicht.

Hat jemand einen Rat?

Re: Kein passender Konstruktor für QImage

Verfasst: Mittwoch 28. September 2011, 23:10
von antimatter
Hat sich erledigt.
Ich hab immer probiert, direkt mit QImage zu arbeiten. Eine QCoreApplication sollte vorher aber noch instanziiert werden. Dann lädt auch das TIF schön...