深入理解各种图片格式

1、位图(bitmap)是bit的数组,指定了一个矩形像素数组中每一个像素的颜色。每一个像素的位宽决定了该像素能表示的颜色数。例如,如果每一个像素用4bits表示,那么该像素就可拥有2^4=16中颜色。下表显示了像素的位宽与颜色种类的关系:

image

 

2、图片文件除了存储每个像素的颜色外通常还会包含一些信息块,这些信息块存放了诸如每个像素的位宽、每一行有多少像素、有多少行等信息,也可能会包含一个颜色表(有时也叫做调色板)。这个颜色表存放了图片所使用的颜色,然后每个像素存放的不是颜色,而是颜色表的索引。例如,以下是一个放大了的图以及它的颜色表和bitmap。每个像素用4位表示,所以颜色表中由2^4=16种颜色,每一种颜色用24位表示,8位给红色,8位给绿色,8位给蓝色。

image

看到2行、2列(从0算起)为1,查颜色表得该像素颜色为红色,所以该像素就为红色。0行全为3,查表知0行像素全为蓝色。

带调色板的位图称为调色板索引位图,有些位图是没有调色板的,每个像素存放的是实打实的颜色值。如下图所示:

image

 

3、各种图片文件格式的解析

a.Bitmap (BMP)——BMP是Windows上常用的与设备和与应用程序无关的标准图片格式。每一个像素的位宽可取为1、4、8、15、24、32或者是64,位宽在BMP文件的文件头中指定,常见的BMP文件一般为24位表示一个像素。

b.Graphics Interchange Format (GIF)——(擅长锐角、线的绘制,无损压缩,背景可透明,但支持的颜色数少)

GIF is a common format for images that appear on Web pages. GIFs work well for line drawings, pictures with blocks of solid color, and pictures with sharp boundaries between colors. GIFs are compressed, but no information is lost in the compression process; a decompressed image is exactly the same as the original. One color in a GIF can be designated as transparent, so that the image will have the background color of any Web page that displays it. A sequence of GIF images can be stored in a single file to form an animated GIF. GIFs store at most 8 bits per pixel, so they are limited to 256 colors.

c.Joint Photographic Experts Group (JPEG)——(非无损压缩、支持颜色数多)

JPEG is a compression scheme that works well for natural scenes, such as scanned photographs. Some information is lost in the compression process, but often the loss is imperceptible to the human eye. Color JPEG images store 24 bits per pixel, so they are capable of displaying more than 16 million colors. There is also a grayscale JPEG format that stores 8 bits per pixel. JPEGs do not support transparency or animation.

The level of compression in JPEG images is configurable, but higher compression levels (smaller files) result in more loss of information. A 20:1 compression ratio often produces an image that the human eye finds difficult to distinguish from the original. The following illustration shows a BMP image and two JPEG images that were compressed from that BMP image. The first JPEG has a compression ratio of 4:1 and the second JPEG has a compression ratio of about 8:1.

Illustration showing a bitmap image and two JPEG compressions of that image; the highest compression has more variation from the original

JPEG compression does not work well for line drawings, blocks of solid color, and sharp boundaries. The following illustration shows a BMP along with two JPEGs and a GIF. The JPEGs and the GIF were compressed from the BMP. The compression ratio is 4:1 for the GIF, 4:1 for the smaller JPEG, and 8:3 for the larger JPEG. Note that the GIF maintains the sharp boundaries along the lines, but the JPEGs tends to blur the boundaries.

Illustration comparing a bitmap of a line drawing to two JPEG equivalents and one GIF; the GIF best preserves color and line sharpness

JPEG is a compression scheme, not a file format. JPEG File Interchange Format (JFIF) is a file format commonly used for storing and transferring images that have been compressed according to the JPEG scheme. JFIF files displayed by Web browsers use the .jpg extension.

e.Exchangeable Image File (Exif)

Exif is a file format used for photographs captured by digital cameras. An Exif file contains an image that is compressed according to the JPEG specification. An Exif file also contains information about the photograph (date taken, shutter speed, exposure time, and so on) and information about the camera (manufacturer, model, and so on).

f.Portable Network Graphics (PNG)——(无损压缩、可包含alpha通道、可融合,自带修正算法,改善在不同设备上的显示效果)

The PNG format retains many of the advantages of the GIF format but also provides capabilities beyond those of GIF. Like GIF files, PNG files are compressed with no loss of information. PNG files can store colors with 8, 24, or 48 bits per pixel and gray scales with 1, 2, 4, 8, or 16 bits per pixel. In contrast, GIF files can use only 1, 2, 4, or 8 bits per pixel. A PNG file can also store an alpha value for each pixel, which specifies the degree to which the color of that pixel is blended with the background color.

PNG improves on GIF in its ability to progressively display an image; that is, to display better and better approximations of the image as it arrives over a network connection. PNG files can contain gamma correction and color correction information so that the images can be accurately rendered on a variety of display devices.

g.Tag Image File Format (TIFF)——(任意的像素位宽)

TIFF is a flexible and extendable format that is supported by a wide variety of platforms and image-processing applications. TIFF files can store images with an arbitrary number of bits per pixel and can employ a variety of compression algorithms. Several images can be stored in a single, multiple-page TIFF file. Information related to the image (scanner make, host computer, type of compression, orientation, samples per pixel, and so on) can be stored in the file and arranged through the use of tags. The TIFF format can be extended as needed by the approval and addition of new tags.

转载于:https://www.cnblogs.com/Wilson-Kwok/archive/2013/01/28/2879511.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值