win32 Bitmaps 介绍 DDB DIB 区别

About Bitmaps

https://docs.microsoft.com/zh-cn/windows/desktop/gdi/about-bitmaps

bitmap 是 GDI objects 中的一个,它可以被选择进入 device context (DC).

Device contexts are structures that define a set of graphic objects and their associated attributes, and graphic modes that affect output.
The table below describes the GDI objects that can be selected into a device context.

Graphic object Description
Bitmaps Creates, manipulates (scale, scroll, rotate, and paint), and stores images as files on a disk.
Brushes Paints the interior of polygons, ellipses, and paths.
Fonts Draws text on video displays and other output devices.
Logical Palette A color palette created by an application and associated with a given device context.
Paths One or more figures (or shapes) that are filled and/or outlined.
Pens A graphics tool that an application uses to draw lines and curves.
Regions A rectangle, polygon, or ellipse (or a combination of two or more of these shapes) that can be filled, painted, inverted, framed, and used to perform hit testing (testing for the cursor location).

从开发者的角度,bitmap是包含很多结构的集合。
该结构包含下列的元素:
header :描述设备上的显示矩形的分辨率,矩形的尺寸,很多位的数组的大小等等。
A logical palette.一个逻辑 调色板
位的数组 定义了位映射的图像的像素 和 逻辑调色板中的条目。
bitmap的大小和图像的类型有关。
位图图像 可以 是单色的,也可以是彩色的。
在每个图像中,每个像素和位图中的一个或者多个位有关。

A bitmap size is related to the type of image it contains. Bitmap images can be either monochrome or color. In an image, each pixel corresponds to one or more bits in a bitmap. Monochrome images have a ratio of 1 bit per pixel (bpp). Color imaging is more complex. The number of colors that can be displayed by a bitmap is equal to two raised to the number of bits per pixel. Thus, a 256-color bitmap requires 8 bpp (2^8 = 256).
Control Panel applications are examples of applications that use bitmaps. When you select a background (or wallpaper) for your desktop, you actually select a bitmap, which the system uses to paint the desktop background. The system creates the selected background pattern by repeatedly drawing a 32-by-32 pixel pattern on the desktop.
The following illustration shows the developer’s perspective of the bitmap found in the file Redbrick.bmp. It shows a palette array, a 32-by-32 pixel rectangle, and the index array that maps colors from the palette to pixels in the rectangle.

这里写图片描述

In the preceding example, the rectangle of pixels was created on a VGA display device using a palette of 16 colors. A 16-color palette requires 4-bit indexes; therefore, the array that maps palette colors to pixel colors is composed of 4-bit indexes as well. (For more information about logical color-palettes, see Colors.)
Note
In the above bitmap, the system maps indexes to pixels beginning with the bottom scan line of the rectangular region and ending with the top scan line. A scan line is a single row of adjacent pixels on a video display. For example, the first row of the array (row 0) corresponds to the bottom row of pixels, scan line 31. This is because the above bitmap is a bottom-up device-independent bitmap (DIB), a common type of bitmap.

In top-down DIBs and in device-dependent bitmaps (DDB),
the system maps indexes to pixels beginning with the top scan line.

Bitmap Classifications

https://docs.microsoft.com/zh-cn/windows/desktop/gdi/bitmap-classifications

There are two classes of bitmaps:
Device-independent bitmaps (DIB). The DIB file format was designed to ensure that bitmapped graphics created using one application can be loaded and displayed in another application, retaining the same appearance as the original.

Device-dependent bitmaps (DDB),
also known as GDI bitmaps, were the only bitmaps available in early versions of 16-bit Microsoft Windows (prior to version 3.0).
However, as display technology improved and as the variety of available display devices increased, certain inherent problems surfaced which could only be solved using DIBs. For example, there was no method of storing (or retrieving) the resolution of the display type on which a bitmap was created, so a drawing application could not quickly determine whether a bitmap was suitable for the type of video display device on which the application was running.
Despite these problems, DDBs (also known as compatible bitmaps) are still useful for better GDI performance and for other situations.

DIB 和DDB的区别 优缺点

Bitmaps, Device Contexts, and Drawing Surfaces

https://docs.microsoft.com/zh-cn/windows/desktop/gdi/bitmaps–device-contexts–and-drawing-surfaces

A device context (DC) is a data structure defining the graphics objects, their associated attributes, and the graphics modes affecting output on a device.

To create a DC, call the CreateDC function;
to retrieve a DC, call the GetDC function.

Before returning a handle that identifies that DC, the system selects a drawing surface into the DC.
If the application called the CreateDC function to create a device context for a VGA display, the dimensions of this drawing surface are 640-by-480 pixels. If the application called the GetDC function, the dimensions reflect the size of the client area.
Before an application can begin drawing,
it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function.
When an application passes the handle to the DC to one of the graphics device interface (GDI) drawing functions, the requested output appears on the drawing surface selected into the DC.
For more information, see Memory Device Contexts.

 DIB不依赖于具体设备,可以用来永久性地保存图象。DIB一般是以.BMP文件的形式保存在磁盘中的,有时也会保存在.DIB文件中。 DIB位图的特点是将颜色信息储存在位图文件自身的颜色表中,应用程序要根据此颜色表为DIB创建逻辑调色板。因此,在输出一幅DIB位图之前,程序应该将其逻辑调色板选入到相关的设备上下文并实现到系统调色板中。
DDB依赖于具体设备,它只能存在于内存中(视频内存或系统内存),其颜色模式必须与特定的输出设备相一致,使用系统调色板。一般只能载入色彩较简单的DDB位图,对于颜色较丰富的位图,需使用DIB才能长期保存。

DDB依赖于具体设备:
DDB的颜色模式必需与输出设备相一致。例如,如果当前的显示设备是256色模式,那么DDB必然也是256色的。
在256色以下的位图中存储的像素值是系统调色板的索引,其颜色依赖于系统调色板。
由于DDB高度依赖输出设备,所以DDB只能存在于内存中,它要么在视频内存中,要么在系统内存中

DIB的与设备无关性主要体现在以下两个方面:
DIB的颜色模式与设备无关。例如,一个256色的DIB即可以在真彩色显示模式下使用,也可以在16色模式下使用。
256色以下(包括256色)的DIB拥有自己的颜色表,像素的颜色独立于系统调色板。
由于DIB不依赖于具体设备,因此可以用来永久性地保存图象。DIB一般是以.BMP文件的形式保存在磁盘中的,有时也会保存在.DIB文件中。运行在不同输出设备下的应用程序可以通过DIB来交换图象

DDB依赖于具体设备,它只能存在于内存中(视频内存或系统内存),其颜色模式必须与特定的输出设备相一致,使用系统调色板。一般只能载入色彩较简单的DDB位图,对于颜色较丰富的位图,需使用DIB才能长期保存。

  DIB不依赖于具体设备,可以用来永久性地保存图象。DIB一般是以.BMP文件的形式保存在磁盘中的,有时也会保存在.DIB文件中。 DIB位图的特点是将颜色信息储存在位图文件自身的颜色表中,应用程序要根据此颜色表为DIB创建逻辑调色板。因此,在输出一幅DIB位图之前,程序应该将其逻辑调色板选入到相关的设备上下文并实现到系统调色板中。

DIB由于自带颜色表,理论上说在不同的设备上显示时均可按原来的颜色还原显示,或仿真显示,但是很明显颜色表需要消耗一定的存储空间,并且在每次显示时均要对颜色进行处理,因此速度较慢。DDB由于直接对颜色位平面进行记录,因此显示速度最快,但是在不同的设备上显示时不能保证颜色的还原。

主要区别就是颜色标,一般来说,在剪贴板中存放的是DDB(比如截屏的时候获得的),在文件中存放的是DIB

网址:

参考 windows 应用源码:
.截图精灵 Capture V1.0
取色精灵 CatchColor V2.0
超级时间助手 SuperTimeHelper V1.0
基于PMAC的两轴轨迹规划软件Spin4.0
基于MIL开发的在线监测、录制和播放软件Grab3.0
http://jimwen.net/tag.php?tag=Capture

我还是云里雾里的啊。
看到一本《VC++图像处理》(何斌,邮电出版)的书,上面第一章就把DIB函数库封装了。以后每章节的程序都调用。可是,我看我师兄师姐的程序,里面并不用调用这个封装的DIB库,而是直接用的一些DIB函数啊。到底为何呢?

痛苦好几天了,感觉越看越头大。请求各位给予帮助。

GetDIBts DDB转换为DIB

SetDIBts DIB转换为DDB

CreateDIBitmap 用指定的DIB创建DDB并且初始化位图图像

CreateDIBSection 创建一个直接可以写入的DIB 也就是说

猜你喜欢

转载自blog.csdn.net/wowocpp/article/details/80830708