Unsolved BMP display in QT c++
-
Hi,
i am trying to display BMP in QT with below code. bmp downloaded correctly but image is not displayed.
fun(){
std::string szUrl("http://guest:p2guest@192.168.55.3/contents/2/icon/0874T2.bmp"); std::wstring wpathURL(szUrl.begin(), szUrl.end()); char *recByte = contmgr->Download(wpathURL.c_str()); QGraphicsScene scene; QGraphicsView view(&scene); QImage img; img.fromData(recByte); // READING DATA QPixmap pic; pic.fromImage(img); QGraphicsPixmapItem item(pic); scene.addItem(&item); view.show();
}
download function works fine, i have tested for other functionality.
please suggest me how to display bmp, what is issue with this code.
-
@shashi-prasad said in BMP display in QT c++:
QImage img;
img.fromData(recByte); // READING DATA
QPixmap pic;
pic.fromImage(img);Not related to your issue, but there is no need to first create a QImage and then a QPixmap. You can create a QPixmap directly.
For your issue make sure have the imageplugins deployed/available.
What does the following return?qDebug() << QImageReader ::supportedImageFormats()
-
QImage QImage::fromData(const uchar *data, int size, const char *format = Q_NULLPTR)
is a static function that returns a QImageQImage img;
img.fromData(recByte); // READING DATAhas no effect on
img
it will remain an null-imagetry
QImage img = QImage::fromData(recByte);
-
output of qDebug() << QImageReader ::supportedImageFormats(); is
("bmp", "cur", "dds", "gif", "icns", "ico", "jp2", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")
output of qDebug()<<"recByte============="<<img.size(); is
recByte============= QSize(0, 0)
i think something wrong so it is showing 0,0.
i used as QImage img = QImage::fromData(recByte);
still output of qDebug()<<"recByte============="<<img.size(); is
recByte============= QSize(0, 0)please suggest me.
-
@shashi-prasad
my guess would be yourrecByte
is empty or has an invalid header. You should check that.Edit: Additional Info
if recByte is not empty check the 14 first Bytes.
0-1 => The header field used to identify the BMP
2-5 => Size of the BMP
6-9 => Reserved for the application that created the bmp file
10-14 => starting address, of the byte where the bitmap image data (pixel array) can be found. -
Hi,
Likely related to this thread.