Qt uses qgraphicview/qpainter to display RGB/YUV Images

Source: Internet
Author: User

This document describes how to use QT for RGB rendering. The author believes that qpainter is better in the Application Scenario of large data volume and few objects for media rendering. in multiple RGB conversions, YUV is least converted to rgb565 and the problem of byte alignment is not easy to occur, therefore, it is recommended.



Compare it with OpenGL ddraw SDL.


RGB-> qimage-> qpixmap-> scene-> grapview



The data of the image is saved in bytes. The number of bytes in each row must be an integer multiple of 4.
(Because we use a 32-bit operating system, the data is 32-bit aligned, therefore, the number of bytes in each row must be an integer multiple of 4, that is, the data bit in each row must be an integer multiple of 32 bits .) This is what I understand. It seems wrong. I fixed it. Recently I was reading data alignment. In this section, I ignored it and didn't delete it because I wanted to leave a footprint, wait until I find a suitable answer and paste it back. However, the image data is indeed 32-bit aligned.
If it is not an integer multiple, the formula is as follows: W = (w * bitcount + 31)/32*4;
Note: W indicates the width of the image, and bitcount indicates the depth of the image, that is, 32 or 24. The calculated W indicates the number of bytes per line of the image in the program.
The 32, 24, and 8 bitmap of qimage are described here.
Image Format: qimage: format_rgb32, qimage: format_rgb888, qimage: format_indexed8.
Construct an image:
(1) qimage myimage1 = qimage (filename); open the Image Based on the file name. If the image itself is 32-bit or 24-bit, the program image is 32-bit, if the image itself is 8-bit and 1-bit, the program corresponds to 8-bit and 1-bit.
(2) qimage myimage2 = qimage (width, height, qimage: Format _...); To construct an image based on the image width and height, the program will automatically align the image data according to the image format.


Reference code:

Int byteperline = (nplaywidth * 24 + 31)/8; // each row of the image is aligned with an unsigned char * graydata = new unsigned char [byteperline * Height]; // store the processed data/* modify the corresponding image data graydata */m_scene-> clear (); qimage * grayimg = new qimage (graydata, nplaywidth, nplayheight, byteperline, qimage:: format_rgb888); m_scene-> addpixmap (qpixmap: fromimage (* grayimg ));

In addition, the rendering of rgb565 is as follows:


QImage *tmp_img=new QImage((uchar *)m_ImgPtr,m_width,m_height,QImage::Format_RGB16);    m_painter->drawImage(*m_point,*tmp_img);





References:

Qt graphics device and graphics view frameworkhttp: // www.oschina.net/question/234345_48854

Qimage image format Summary

Http://tracey2076.blog.51cto.com/1623739/539690/

Use stretchdibits to display on picturebox skew

Http://bbs.csdn.net/topics/300245493

Grayscale Images can be normally displayed using setpixel, and images drawn by stretchdibits are skewed.

Http://blog.csdn.net/zhongjling/article/details/7583376

Qimage processing of general images

Http://www.cnblogs.com/Romi/archive/2012/12/03/2800039.html



Qt uses qgraphicview/qpainter to display RGB/YUV Images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.