Solved

DDB VS. DIB Questions

Posted on 1998-02-03
4
1,150 Views
Last Modified: 2013-12-03
This is not a question about the difference between DDBs and DIBs.  So don't explan that.

What I am asking about is there use.  I was under the impression that DIBs were used for permanent storage and that a program must load them and convert them to DDBs for use with a particular DC.

However I read some microsoft documentation that said that DDBs are just for compatibility with old applications and the newer applications should only use DIBs.  

Is that true?  

If so, can a DIB be selected into a DC just like a DDB?  
Given arrays of color and pixel information how do I create a DIB and get a handle to it?  The functions I've found seem to create DDBs.

If I need to repeatidly display a DIB image, it is best to convert it to a DDB and display that repeatidly?
0
Comment
Question by:nietod
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1410822
DIB should be used since they are displayed considerably better then DDB as windows performs color adjusting before actually blit image. In case of DDB data is simply copied to wideo memory so drawing DDB is much faster then DIB. You don't need to select DIB into any DC since DIB is raw data plus optionaly palette. DDB is handle(HBITMAP) to internal structure and you can operate with it only via this structure what oppose to DIB where you can direct access to bits. To create DIB in general you must allocate memory block which is width*height*biBitCount/8 + sizeof(BITMAPINFOHEADER) bytes with GlobalAlloc. Then you must fill in BITMAPINFOHEADER structure. If you have 24 or 32 bit DIB so no palette needed. Then you can directly set bits by copying memory to allocated block with necessary offset. Also you can use GetDIBits function to set DIB bits but this function has disadvantage as it takes DC so DIB you can create by such a way is DC dependent.
0
 
LVL 22

Author Comment

by:nietod
ID: 1410823
I appreciate your comments.  They were helpful, but they still left an important question unanswered.

I still need to know how do you work with a DIB.  It sounds like you allocate and define it in your programs  memory so you don't have a handle to it like you do for a DDB.  I assume that means it does not get selected into a device context.  So how do you use it?  For example, how do you draw it and how can you draw to it?
0
 
LVL 7

Expert Comment

by:galkin
ID: 1410824
I allocate memory using GlobalAlloc which return handle to global memory block of type HANDLE which can be considered as DIB handle. Actually DIB doesn't have have true handle like DDB since all function that operate with DIB operate with raw data( DIB bits) and DIB desription which is BITMAPINFOHEADER structure explaining how to treat this raw data. You cannot "draw" onto DIB as I am sorry for repeating it is raw data so you can change it by changing raw data. This is memory block so apply the same methods you would apply to change values of memory block. These is no analogy with DDB's selecting into memory DC and drawing on it and then blitting onto actual DC. To draw various shapes and lines "on DIB" you must directly change values of corresponding bits. There are to functions SetDIBitsToDevice and StretchDIBits which set DIB, i.e. raw data(BITMAPINFOHEADER followed by bits themselves) to target DC.
0
 
LVL 22

Author Comment

by:nietod
ID: 1410825
thanks,  

I'll try fooling with this tommorrow.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Search and Edit Form 6 71
Asp.net Form view Pager Template First Record 2 70
Problem to packaging 1 81
Dialogbox API leak? 18 80
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short film showing how OnPage and Connectwise integration works.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now