Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not work QImage::loadFromData
Forum Updated to NodeBB v4.3 + New Features

Not work QImage::loadFromData

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 389 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by Mihaill
    #1

    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.04

       QPixmap 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

    JonBJ 1 Reply Last reply
    0
    • M Mihaill

      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.04

         QPixmap 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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Mihaill said in Not work QImage::loadFromData:

      file.open(QIODevice::ReadOnly | QIODevice::Text);

      It may not matter under Linux, but for sure you do not want QIODevice::Text here. First start by removing that.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mihaill
        wrote on last edited by
        #3

        It is work!

        JonBJ 1 Reply Last reply
        0
        • M Mihaill

          It is work!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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 bytes 0x0d 0x0a somewhere that would get changed to just 0x0a, which I guess was the case.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved