Nowadays, the pixels of the rear camera of smart phones are getting higher and higher. For a 24-bit depth map with 20 million pixels, if 100% is not compressed, the storage space of this photo is as high as 57.2M, such as BMP format, which will greatly waste our storage space.
So algorithm scientists invented various advanced algorithms to formulate new image formats, such as jpg, png, gif and so on.
compression algorithm
Among them, jpg adopts lossy compression algorithm, and the compression ratio can be customized. When we use Photoshop to store jpg format, we can choose the storage quality of the picture, which is 0~ 12, which is actually a user-defined compression ratio. The higher the compression ratio, the smaller the storage space of the final picture and the greater the detail loss.
Although jpg uses lossless compression, when the compression quality is above 9, the image display quality is still quite good, even it is difficult for the naked eye to distinguish. Photos taken by smart phones are generally high-quality jpg by default. For 20 million pixel landscape photos, the storage size obtained by the default compression algorithm of the camera is about 10M.
However, png uses lossless compression algorithm. When we stored png format in Photoshop, we didn't choose to customize the image quality. In most cases, the storage space of the same photo png is larger than that of jpg.
However, when images use less colors, the compression algorithm in png format is more advantageous, and even the storage space is smaller than that in jpg. Png is basically equivalent to compressing a file into zip format, but this file is just a picture.
Transparent channel
The biggest difference between png and jpg is that png supports alpha channel, which is what we call transparent channel, while jpg does not support transparent channel, which makes png format have special uses in some occasions.
For example, the computer application icon, we will find that the edge of the icon is transparent, and we can see the desktop background behind it. If we find the icon file of the program, we will find that the icon format is usually png, which is one purpose of the transparent channel, but jpg format cannot be realized.
If we use Photoshop to save a picture with transparent channels in jpg format, then the original transparent channels will be treated as a white background.
Moreover, the png format also supports translucency, and the alpha channel has 256 transparency options, which greatly increases the application scope of the png format.
For friends who do design, we often use the transparent functions of png, such as company icons or words. We all save them in png format, so as to avoid matting when we use them next time.
In terms of experience, png and jpg have three obvious differences:
1 and png support transparency and translucency; Jpg does not support it.
2.png is lossless compression; Jpg is lossy compression, and the compression ratio can be customized.
3. In most cases, the same photo png will take up more storage space.