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

Displaying Buffer data on Qlabel



  • Hi,
    I have a buffer data of color format YUY2 /UYVY/NV12/NV21 etc.

    How do I display/render the buffer using qlabel??


  • Lifetime Qt Champion

    Hi,

    You'll have to convert it to one of the supported QPixmap type first.



  • @SGaist
    Thank you for your reply.

    Below is my code for displaying/rendering "RGB" buffer on a Qlabel.

         QImage  *img = new QImage(camera->width ,camera->height, 
         QImage::Format_RGB32);
    
     uint8_t *l_ui_arr = new uint8_t[g_size_v4l2];
     if (!l_ui_arr)
     {
        qDebug() << "Memory allocation failed for arr\n";
     }
    
     camera->head.start // This is my buffer
     g_size_v4l2 // The size of the buffer
    camera->height // Height of my image
    camera->width // width of my image
    
    memcpy(l_ui_arr,camera->head.start,g_size_v4l2);
    for(uint32_t l_height = 0; l_height < camera->height; l_height++)
    {
      for(uint32_t l_width = 0; l_width < camera->width; l_width++)
      {
           QRgb value = qRgb(l_ui_arr[l_ui_arrayIndex], l_ui_arr[l_ui_arrayIndex+1], l_ui_arr[l_ui_arrayIndex+2]);
           l_ui_arrayIndex = l_ui_arrayIndex+3;
           img->setPixel(l_width, l_height,value);
      }
    }
    ui->label->setPixmap(QPixmap::fromImage(*img,Qt::AutoColor));
    

    Now, when I get buffer of any other format such as NV12/NV21/UYVY etc.

    How do I convert it to the supported QPixmap type??



  • You probably have to do the conversion from NV12/UYVY etc to RGB yourself then generate the pixmap.
    There's lots of code available to show how to do this. Check StackOverflow.


Log in to reply