Differences between createdibsection and createdibitmap -- a detailed discussion

Source: Internet
Author: User

Createdibsection and createdibit
Difference of Map-detailed discussion

[The post has been closed. The end user is wonaixiaogang]

.
[Chinasoft network]

Programming Forum
  Landlord
Many people say that the conversion between IDB and DDB is slow, so we use createdibsection () to create a Dib block. In this way, the drawing speed is fast.
Createdibsection () returns an hbitmap, while createdibitmap () returns hbit
Map.
The difference between the two is that createdibsection creates a dibsection structure, while createdibitmap creates a bit
Map structure.
----------------------------------------------------
What is dibsection? Let's look at its structure:
Typedef struct tagdibsection {
Bit
Map dsbm;
Bit
Mapinfoheader dsbmih;
DWORD dsbit
Fields [3];
Handle dshsection;
DWORD dsoffset;
} Dibsection, * pdibsection;
As you can see, it contains a bitmap structure, a Dib information header bitmapinfoheader, and a mask table dsbit.
Fields [3].
There is also a memory ing file handle and offset. We ignore the last two fields.
Therefore, the hbit function returned by createdibsection () is used
There is no problem with map construction.
-------------------------------------------------------------------------
What I don't understand is that since we can use createdibit
Map () to get DDB from Dib. Why does Microsoft need to create a createdibsection () (in addition to the memory ing file function )?
Is the plotting efficiency of this function different? If so, why. In my opinion, the difference between DiB and DDB is that the information header is different. Bitmapinfoheader and bit
Map, and one with a color table, and the other without a color table. The bitmap data of DiB and DDB is exactly the same.

Please advise me.

.
[Chinasoft network]

Programming Forum
 1
A netizen replied:
Createdibitmap the DDB that is created will be whatever bit
Depth your reference DC is.
Createdibsection to create a bitmap that is of different bit
Depth

.
[Chinasoft network]

Programming Forum
 2
 
A netizen replied:

First, you need to understand the difference between DiB and DDB. For the conversion from DDB to Dib, you only need to add a Bitmap header. But the conversion from DIB to DDB is as follows, based on the current DC bitmap format
(How many bits of color), you may need to expand or reduce the number of bits of colors. If you consider this factor, you can consider it as a loss of speed. Therefore, DDB plot in GDI must be the fastest, directly copying bitmap data
To the video memory.

.
[Chinasoft network]

Programming Forum
 3
A netizen replied:
The reply was deleted by the Moderator at 10:13:11.

.
[Chinasoft network]

Programming Forum
 4
A netizen replied:
In a word, createdibsection () is easy to control, because the bitmapinfo you construct is based on the bit value.
To operate its BIT data.
While createdibitmap () and create are DDB, which have the same color as the screen. On this machine, it may be 16bit, while on that machine it may be 24bit or 32bit.
Is not conducive to code control/maintenance ..

When createdibsection () is used, an LPB is input.
It
MapInfo and a null const void ** pointer, once created, you can directly manipulate that bit of Data Pointer (const void, you don't need to worry about how it is converted to DDB.

However, dib must be slower than DDB because it must be converted to DDB.
========================================================== ==================
Hbitmap = createdibsection (HDC, (const bit
MapInfo *) LPB
Minfo, dib_rgb_colors,
(Void **) & Pb
It
S, null, 0 );

// Once you create a file, you can directly control the Pb
It
S pointer, for example:

Memset (PB
It
S, 0x0, imagesize); // black all or
* (PB
It
S + XXXX) = 255; // assign a value to a pixel.

========================================================== ======================
This method is convenient, so many people will use this method, and it is quite easy to save it as a file. There are bitmapinfo and BIT data pointers, and fill in a bit
Mapfileheader can be written as a BMP.

.
[Chinasoft network]

Programming Forum
 5
A netizen replied:
On the 4th floor, according to your statement, I think you are right:
When the fourth parameter is dib_rgb_colors, the dib created by createdibsection () does not use the HDC color depth, which is incompatible with HDC. Then we directly use hbit returned by createdibsection ()
During map construction, it may fail or be wrong.
When the fourth parameter is dib_pal_colors, the bitmap color depth is compatible with HDC. In this case, we use LPB
The color depth specified by minfo is invalid. In this case, you cannot directly save DIB to the file.
If I understand the error, please explain it, But DC and LPB
When the color depth of minfo is different, how does createdibsection () work. Thank you.

.
[Chinasoft network]

Programming Forum
 6
A netizen replied:
Always specify dib_rgb_colors.
Because any
Map (DDB) changes will be reflected in its data block (the const void ** pointer ).

For example, you use the createdibsection () function to create an hbit
You can directly select the memory DC drawing, and then save it directly, because all the changes are recorded in the Data Pointer:
HDC = getdc (null );
Hbitmap = createdibsection (HDC, (const bit
MapInfo *) LPB
Minfo, dib_rgb_colors,
(Const void **) & Pb
It
S, null, 0 );

HDC hmemdc = createcompatibledc (HDC );

Hbitmap holdbmp = (hbitmap) SelectObject (hmemdc, hbit
Map );
Drawcodehere ().....
Drawagain ().....
// Release

SelectObject (hmemdc, holdbmp );
Deletedc (hmemdc );
Release
DC (null, HDC );
// You can save it or save it ..
Bit
Mapfileheader bmfh;
Bmfh. bftype = 0x4d42;
.........
.....
..
========================================================== ========================================
It is absolutely irrelevant to the device. It will never fail because it is different from the device, so it is almost used to construct CDIB and so on.

Of course, if the processing is 8bit
Or the following BMP, you also need to set the color palette (palette) and color table (colors table) Code

.
[Chinasoft network]

Programming Forum
 7
A netizen replied:
Dizzy.
What is the structure of DDB? Besides a bit
Besides the map information header, is there only a data zone?
What format is the data zone? Is it a 4-byte, one-pixel RGB format, or is each pixel pointing to the index value of the DC color table?
If DDB data is in 32-bit, 1-pixel RGB format, and DC is an 8-bit, 256-color disk. Will the data region be converted when DDB is selected as DC?
If no conversion is made, isn't it possible to use DC to plot the color wrong?

.
[Chinasoft network]

Programming Forum
 8
A netizen replied:

Reference the reply from wonaixiaogang on the 7th floor:

Dizzy.
What is the structure of DDB? Besides a bit
Besides the map information header, is there only a data zone?
What format is the data zone? Is it a 4-byte, one-pixel RGB format, or is each pixel pointing to the index value of the DC color table?
If DDB data is in 32-bit, 1-pixel RGB format, and DC is an 8-bit, 256-color disk. Will the data region be converted when DDB is selected as DC?
If no conversion is made, isn't it possible to use DC to plot the color wrong?

DDB is very simple. What is the color of your system? What is the color depth.
Your system is set to 24bit true color, and DDB is set to 24bit true color. If you set 16 or 32bit, DDB is 16 or 32bit.
.
There will be no 32-bit DDB, while DC is 8-bit.
DC is like your screen, while DDB is like a graph displayed on the screen. The figure displayed on the screen is bit (color depth) and DDB is bit.
DDB is device-related.

.
[Chinasoft network]

Programming Forum
 9
A netizen replied:

Reference the reply from lambochan on the eighth floor:

There will be no 32-bit DDB, while DC is 8-bit.

In this case, what is the use of DC?
The screen is different from the DC of the printer. Creating a compatible bitmap means creating a bitmap compatible with the DC, and passing in the DC parameter.
DC has 8 bits, and DDB has 32 bits, depending on the bit of DC you pass in.
Why do many functions of GDI use HDC input parameters? Because DC may be different.
After reading this online, when the 3rd parameters of createdibsection () Use dib_rgb_colors,
The Dib created by createdibsection () is composed of a 4-byte, one-pixel RGB value. It does not use the HDC color depth and is incompatible with HDC.

.
[Chinasoft network]

Programming Forum
 10
A netizen replied:
Of course, I may be wrong, or maybe, when the 3rd parameters of createdibsection () Use dib_rgb_colors,
The Dib created by createdibsection () is directly compatible with the DC of the screen, that is, the system color depth is used,
However, in this case, the color depth of the input HDC is not used, and it may be incompatible with HDC.

.
[Chinasoft network]

Programming Forum
 11
A netizen replied:
Dizzy .. DC certainly has eight bits, because the device is eight bits ..
Similarly, DDB also has 32-bit.

Simple: Use createcompaiblebitmap () to create a bit
Map it out, and then GetObject () will know the number of devices, because the created DDB is device-related.

The same machine, DC is absolutely the same.

"The Dib created by createdibsection () is composed of a 4-byte, one-pixel RGB value. It does not use the HDC color depth and is incompatible with HDC. "
Of course not. For the create 8-bit BMP, take its Dib Data Pointer for processing. Each pixel is still one byte, and the 24-bit value is three bytes.
Unless you use GetObject () in a 32-bit color-Depth System to retrieve the bit of hibmtap.
The DDB data pointer in the map structure is 4 bytes of rgbx data.

We recommend that LZ check the weekly hair <proficient in Visual C ++
. Net
Image processing Programming
>. Or Google search DDB & DiB and DC concepts

.
[Chinasoft network]

Programming Forum
 12
A netizen replied:

Reference the reply from lambochan on the 11 th floor:

The same machine, DC is absolutely the same.

You always say some one-sided sentences.
On the same machine, the dc I created may be different from the screen DC.

Reference the reply from lambochan on the 11 th floor:

Of course not. For the create 8-bit BMP, take its Dib Data Pointer for processing. Each pixel is still one byte, and the 24-bit value is three bytes.
Unless you use GetObject () in a 32-bit color-Depth System to retrieve the bit of hibmtap.
The DDB data pointer in the map structure is 4 bytes of rgbx data.

You mean: the pointer and GetObject () returned by the dib data created by createdibsection () are used to retrieve the bit of hibmtap.
Is the DDB data pointer in the MAP Structure pointing to a different location?
I tried to prove that the two pointers point to the same position.

.
[Chinasoft network]

Programming Forum
 13
A netizen replied:
Lab code:

C/C ++
Code
   
Void * GMM;
Void * ppv2;
Bitmap B;
Hbitmap = createdibsection (null, (bitmapinfo *) pbuf, dib_rgb_colors, & GMM, null, null );
GetObject (hbitmap, sizeof (Bitmap), & B );
Ppv2 = B. bmbits;
If (GMM = ppv2)
{
Trace ("same/N ");
}
Else
{
Trace ("different/N ");
}

 

.
[Chinasoft network]

Programming Forum
 14
A netizen replied:
Now I seem to understand a little bit:

The first HDC parameter and the second bit parameter of createdibsection ()
The color depth of MapInfo must be the same. The function succeeds only when dib_pal_colors is used. This is because:

When dib_pal_colors is used, the HDC color table is copied to the color table in dibsection of DiB. When dib_rgb_color is used,
The Dib color table retains the default color table.

I don't know if I'm right. I rely on it. The information on this function and msdn are not clear. People who use it seem to understand and will use it.

.
[Chinasoft network]

Programming Forum
 15
A netizen replied:
It just shows that the dib created by createdibsection () is not related to the device from the inside out... although I thought it was the bit of hbitmap.
The map structure has been converted to DDB.
But what then? As you said, its pixels are composed of four bytes of rgbx.
It is still one byte for 8 bits (color table index) and two bytes for 16 bits, which is absolutely device independent.
In the above plot, it will not change because of the system color depth, still 8 bit, 8 bit, 24 BIT or 24 Bit
.

Let's talk about your DC... since you are talking about the DC you created, what is different from the screen ..
It is estimated that you are talking about createdc (), and even do not know what Dc you create.
However, the DDB color depth displayed on the screen must be the same as the color depth set by the display device.

.
[Chinasoft network]

Programming Forum
 16
A netizen replied:
Traditionally, DC is the context of the screen device.
Even though it is the same, it is because getdc () is usually used to obtain the DC for display. The color depth obtained must be the same on one machine ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.