Qimage screenshot von einen externen Gerät einlesen und speichern
-
Hallo zusammen,
ich habe einen Application bei dem ich mich mit einem Oscilloscope verbinde.
Diese Art der Verbindung ist basiert auf einen Standarisierte "VISA" Interface.
"https://en.wikipedia.org/wiki/Virtual_Instrument_Software_Architecture"
Die Verbindung zu den Osci ist keine Problem. Befehle könnten auch ausgeführt werden.
Nun möchte ich einen Screenshot speichern und in GUI darstellen, da klappt irgendwie nicht.An bei meinen Codeabschnitt:
Die Klasse (AgilentVisa), die für die Verbindung mit der oscilloscope zuständig ist:/* *getter und setter von Visa queryResponce */ QByteArray getScreenshot() { return this->_queryVisaResult; } void setScreenshot(QByteArray queryVisaResult) { this->_queryVisaResult = queryVisaResult; } int VisaAgilent::writeQuery(const QString &qCommand) { ViStatus status; QString command; QByteArray qBaCommand; char viCommand[256]; char* viCommandUC; int writeCount; ViChar desc[256]; command = qCommand + "\n"; qBaCommand = command.toLatin1(); strcpy_s(viCommand, qBaCommand.constData()); viCommandUC = (char *)viCommand; char outputBuffer[256]; status = viPrintf(_instr, viCommandUC); if (status < VI_SUCCESS) { viStatusDesc(_instr, status, desc); _statusMsg = QString("Error ViPrintf to the device: %1").arg(desc); setMessage(_statusMsg); emit statusUpdate(_statusMsg); return -1; } else { status = viScanf(_instr, "%#b\n", &writeCount, _buffer); if (status < VI_SUCCESS) { viStatusDesc(_instr, status, desc); _statusMsg = QString("Error viScanf to the device: %1").arg(desc); setMessage(_statusMsg); emit statusUpdate(_statusMsg); return -1; } _statusMsg = QString("viScanf completed with %1 characters read").arg(writeCount); setMessage(_statusMsg); emit statusUpdate(_statusMsg); setScreenshot(_buffer);//_buffer beinhaltet das ScreenshotObject emit pictureChanged(QString(_buffer)); return VI_SUCCESS; }
Von der GUI Seite:
void MainVisaConnection::getReadSystemSetting() { if (VisaAgilent::instance()->writeQuery(":DISPLAY:DATA? BMP8BIT, SCREEN, COLOR") < VI_SUCCESS) showErrorDialog(); QImage img_l; QPixmap* pixmap; QPixmap image; QSize S; bool test = false; S = ui.labImage->size(); image = pixmap->scaled(S, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); test = img_l.loadloadFromData(VisaAgilent::instance()->getScreenshot(), "PNG"); ui.labImage->setPixmap(QPixmap::fromImage(img_l)); }
Was mache ich den falsch?
-
@Galilio said in Qimage screenshot von einen externen Gerät einlesen und speichern:
test = img_l.loadloadFromData(VisaAgilent::instance()->getScreenshot(), "PNG");
hier ist einen Tippfehler:
test = img_l.loadFromData(VisaAgilent::instance()->getScreenshot(), "PNG");
Bei der Aufruf von diese FKT bekomme ich immer false zurück
Wenn es alle Okay wäre muss ich einen True zurückbekommen. -
Hi,
du gibst bei img_l.loadFromData... als Format "PNG" an. Das Format in deiner Abfrage ist aber ein Bitmap-Format.test = img_l.loadFromData(VisaAgilent::instance()->getScreenshot(), "BMP");
oder
test = img_l.loadFromData(VisaAgilent::instance()->getScreenshot());
sollten funktionieren.
Gruß
Gerd -
Bei der Übergabe der Daten an setScreenshot wird automatisch ein QByteArray aus dem char-array erzeugt.
Hier der Auszug aus der Dokumentation:QByteArray::QByteArray(const char *data, int size = -1) Constructs a byte array containing the first size bytes of array data. If data is 0, a null byte array is constructed. If size is negative, data is assumed to point to a nul-terminated string and its length is determined dynamically. The terminating nul-character is not considered part of the byte array.
Wenn du keine Größe angibst wird Dein char-Array nur bis zum ersten 0-Byte übernommen. Durch die Angabe der Größe werden alle Bytes aus deinem char-array in das QByteArray übernommen.
Gruß
Gerd