Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QImage::loadFromData



  • QImage::loadFromData(const uchar * data, int len, const char * format = 0)
    what is exactly the len is? byte? how about the pitch?
    i use this API to load a memory data of DDS file with MipMap...
    but whatever i tried, all failed......

    anyone know any successful demo of use this API?


  • Lifetime Qt Champion

    Hi,

    As an example take a web server that streams jpg images, you can build a QImage from the data received (once you have all the data that is)



  • @SGaist sorry? but i am not quite sure i know what u mean...
    i just doubt that i send a wrong len as the param.... but i dont know what is the right value that should be set, as for a DDS file with Mipmap, considering the Pitch.....


  • Lifetime Qt Champion

    Len should be number of byte of your image. Using this function, Qt will try to guess the format unless you give it him and use the proper reader if it has one for that format



  • but when i tried to load a DDS file which is BC5 with mipmap, always failed....
    so i wonder if i set the wrong len, considering the Pitch...
    how to set the len if there is a Pitch?


  • Lifetime Qt Champion

    What error message do you get ?



  • just return false....and so i donot know what error it was...


  • Lifetime Qt Champion

    Did you check that you have the dds plugin ?



  • i donot use dds plugin...i use my own way to open the image file and copy the memory to the QImage through QImage::loadFromData


  • Lifetime Qt Champion

    loadFromData expects an Image of a known format, or you should provide your own plugin to read the data. If you want to use raw bytes then you should use one of the QImage constructors dedicated to that.



  • the format i do know, is DDS...but it's DDS BC5...and the plugin can't show it...that's why i have to copy the memory to the QImage by myself...
    how can i use one of the QImage constructors dedicated to that ??
    i am not quite sure about this....is there example?


  • Lifetime Qt Champion

    As silly as it may sound, just provide the data the specific constructor needs to have



  • `
    QImage(uchar * data, int width, int height, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)

    QImage(const uchar * data, int width, int height, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)

    QImage(uchar * data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)

    QImage(const uchar * data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)

    QImage(const char * const[] xpm)
    `



  • use these two?
    QImage(uchar * data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)

    QImage(const uchar * data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)


Log in to reply