pixmap to bytearray, bytearray to pixmap
-
Use the grab() function of the chart viewer to get it as a pixmap. And save it as a bytearray in xml.
When I load the file and put it in qlabel, the message QPixmap::scaled: Pixmap is a null pixmap occurs.QByteArray bArray; QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); this->m_pChartViewer->grab().save(&buffer, "PNG"); QPixmap fromBase64; fromBase64.loadFromData(src.pixByte); this->ui.label->setPixmap( fromBase64.scaled( nw, nh, Qt::KeepAspectRatio, Qt::SmoothTransformation) );
Is there any way to solve it?
The loadFromData function is returning false.
I think this is the problem... -
How do you save and read it in to/from the xml?
-
QS_FIELD(QByteArray, pixByte) // pixByte QByteArray bArray; QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); this->m_pChartViewer->grab().save(&buffer, "PNG"); m_pStcInfo->pixByte = bArray;
It has a bytearray as a member variable of the class.
Assign here and save the value of the member variable of this class in xml format.===============================================================================
<pixByte>�PNG </pixByte>I have captured the contents stored in the xml file.
-
You can/must not simply but a QByteArray in a xml - you have to encode it e.g. as base64 and decode it later on.
-
Thank you for answer. Thanks it has been resolved.
When I save it as tobase64, the size of the file has definitely increased.
I think it was probably because of a lot of text. Is there any way to reduce the file size?The method I tested was to save it as a QString, then convert it to tobase64() and convert it back to frombase64.
But I didn't see the results I wanted.
Is there any way to reduce the file size? -
@IknowQT said in pixmap to bytearray, bytearray to pixmap:
When I save it as tobase64, the size of the file has definitely increased.
I would be surprised if not - now only 64 instead 256 characters are used (only the really printable ones) - see https://en.wikipedia.org/wiki/Base64
Is there any way to reduce the file size?
Reduce the size of the picture, don't store pictures in xml.