Article directory
jpg
and png
image format
Before writing this article, the author encountered such a problem when writing a simple Qt program:
Problem: QLabel cannot read when a
png
picture 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 , ,jpg
and all of them aresetStyleSheet()
QImage
QPixmap
QLabel
failend.
Hereby study the difference between this jpg
and png
the two, and then study Qt's question about reading pictures in related formats.
There are two formats of pictures jpg
and pictures png
, so what is the difference between the pictures in these two formats? Let me share it with you. png
and jpg
are commonly used image formats, which png
belong to lossless compression jpg
and 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.
jpg
Format
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:
- high compression ratio
- Lossless and lossy compression
- progressive transfer
- Region of interest compression
- Random access and processing of code stream
- fault tolerance
- content-based description
png
Format
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:
- small volume
- lossless compression
- indexed color mode
- More optimized network transmission display
- Support transparent mode
png
A 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: png
andjpg
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:
jpg
A 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. Thepng
characteristic of pictures is that they are small in size and save space.jpg
Compared with pictures,png
pictures are losslessly compressed. Without losing picture data, you can quickly get the picture you want, and the quality of the picture will not decrease.png
Format pictures can be edited, such as fonts, lines, etc. in the picture, which can be changed by software such as ps. Butjpg
the picture in the format cannot be changed,png
and the picture in the format is largerjpg
than the picturepng
.