[Qt] Pictures in png and jpg formats (1)

jpgand pngimage format

Before writing this article, the author encountered such a problem when writing a simple Qt program:

Problem: QLabel cannot read when a pngpicture in a format is changed to a picture with a suffix in the format. The author has tried to set the picture after changing the suffix to , through the interfaces of , , jpgand all of them aresetStyleSheet()QImageQPixmapQLabelfailend.

Hereby study the difference between this jpgand pngthe two, and then study Qt's question about reading pictures in related formats.

There are two formats of pictures jpgand pictures png, so what is the difference between the pictures in these two formats? Let me share it with you. pngand jpgare commonly used image formats, which pngbelong to lossless compression jpgand lossy compression. The most obvious difference between the two in use is:

  • png supports transparent channel
  • jpg pictures are more suitable for dissemination and use in the network.

jpgFormat

jpg: It is the product of the JPEG standard, and it is also the most popular picture format on the Internet. The picture in jpg format can compress the image file to the smallest format. As the ratio increases, the image quality will gradually decrease. The standard of jpg that we commonly use now is the whole process JPEG 2000标准, which has the following characteristics:

  1. high compression ratio
  2. Lossless and lossy compression
  3. progressive transfer
  4. Region of interest compression
  5. Random access and processing of code stream
  6. fault tolerance
  7. content-based description

pngFormat

PNG: It is a bitmap mode using a lossless compression algorithm. Its design purpose is to replace the GIF and TIFF file formats, and at the same time add some features that the GIF file format does not have. PNG uses a lossless data compression algorithm derived from LZ77, which is generally used in JAVA programs, web pages or S60 programs. The reason is that PNG has a higher compression ratio and a smaller file size. PNG images also have some features:

  1. small volume
  2. lossless compression
  3. indexed color mode
  4. More optimized network transmission display
  5. Support transparent mode

pngA few more things to note about the format:

The PNG format has three forms: 8-bit, 24-bit, and 32-bit. Among them, 8-bit PNG supports two different forms of transparency (index transparency and alpha transparency), 24-bit PNG does not support transparency, and 32-bit PNG is increased on the basis of 24-bit. An 8-bit transparency channel is provided, so 256 levels of transparency can be displayed.

The numbers behind PNG8 and PNG24 represent the maximum color values ​​that can be indexed and stored in this PNG format. 8 represents 2 to the 8th power, which is 256 colors, and 24 represents 2 to the 24th power, which has more than 16 million colors.

Difference: pngandjpg

Transferred from Baidu Encyclopedia:

1. JPEG can produce smaller files for photographic (or similar) images, this is due to JPEG using a specific lossy encoding method for photographic images, which is suitable for low contrast, smooth color transitions in images, and high noise , and the structure is irregular. If PNG is used instead of JPEG in this case, the file size will increase considerably, while the improvement in image quality will be limited. Correspondingly, if you save text, lines, or similar images with clear edges and large areas of the same color, the compression effect of the PNG format is much better than that of JPEG, and there will be no image loss in high-contrast areas like JPEG. If the image has both sharp edges and the characteristics of a photographic image, there is a trade-off between the two formats. JPEG does not support transparency.

2. Since JPEG is lossy compression, iterative loss will occur, and information will be continuously lost in the process of repeated compression and decoding, which will degrade the image quality. Since PNG is lossless, it is more suitable for saving images that will be edited. Although PNG compression for photo images is also effective, there are lossless compression formats designed specifically for photo images, such as lossless JPEG2000, Adobe DNG, etc. In general, none of these formats are suitable for all images. For the image to be released, it can be saved as JPEG, and encoding with JPEG once will not cause obvious image loss.

The summary is:

  1. jpgA picture in the format can display very rich and vivid images while having a high compression ratio, but as the compression ratio increases, the quality of the picture will gradually decrease. The pngcharacteristic of pictures is that they are small in size and save space. jpgCompared with pictures, pngpictures are losslessly compressed. Without losing picture data, you can quickly get the picture you want, and the quality of the picture will not decrease.
  2. pngFormat pictures can be edited, such as fonts, lines, etc. in the picture, which can be changed by software such as ps. But jpgthe picture in the format cannot be changed, pngand the picture in the format is larger jpgthan the picture png.

Guess you like

Origin blog.csdn.net/Fuel_Ming/article/details/124397567