Not work QImage::loadFromData
-
Hi!
Not work QImage::loadFromData and QPixmap::loadFromData.
For example I read image and getting QByteArrat set for QImage, but it's not work.
How I can fix this?
I use qt 6.3 and ubuntu 20.04QPixmap pixmap; QFile file("/home/owner/Загрузки/image_2022-02-04_15-52-48.png"); file.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray arr = file.readAll(); file.close(); QImage image; QImage image2("/home/owner/Загрузки/image_2022-02-04_15-52-48.png"); image.loadFromData(arr); pixmap.loadFromData( arr, "PNG"); qDebug()<<1111<<image.width()<<image.height(); qDebug()<<222<<pixmap.width()<<pixmap.height(); qDebug()<<333<<arr.size()<<image2.format();
image2 have normal size and have format QImage::Format_ARGB32
-
Hi!
Not work QImage::loadFromData and QPixmap::loadFromData.
For example I read image and getting QByteArrat set for QImage, but it's not work.
How I can fix this?
I use qt 6.3 and ubuntu 20.04QPixmap pixmap; QFile file("/home/owner/Загрузки/image_2022-02-04_15-52-48.png"); file.open(QIODevice::ReadOnly | QIODevice::Text); QByteArray arr = file.readAll(); file.close(); QImage image; QImage image2("/home/owner/Загрузки/image_2022-02-04_15-52-48.png"); image.loadFromData(arr); pixmap.loadFromData( arr, "PNG"); qDebug()<<1111<<image.width()<<image.height(); qDebug()<<222<<pixmap.width()<<pixmap.height(); qDebug()<<333<<arr.size()<<image2.format();
image2 have normal size and have format QImage::Format_ARGB32
-
@Mihaill
LOL, I did not expect that to actually work, just that it was wrong,.png
is certainly not a text file.I suspect that even under Linux
QIODevice::Text
will translate precisely the sequence\r\n
to\n
? So if in your.png
there happens to be bytes0x0d 0x0a
somewhere that would get changed to just0x0a
, which I guess was the case.