Drawing DIBs considerations

Win32 Programming

    Next

  • 1. Possible GDI bug(need Microsoft to clarify)
    Hi, Following lines of code puts two records GDI call SetWorldTransform(hdc , &xform); puts a EMRSETWORLDTRASNFORM record and a EMRMODIFYWORLDTRANSFORM record with iMode as 4 but xform is the same as in the SETWORLDTRANSFORM record. iMode of 4 is not defined in sdk. I want to know if it is a bug in GDI code or Is the record deliberately added. Thanks Vipin
  • 2. CS_OWNDC style
    In Charles Petzold's 5 star book - <<Programming Windows>>, he said: Although this approach is generally satisfactory, you might prefer that changes you make to the attributes be saved when you release the device context so that they will be in effect the next time you call GetDC or BeginPaint. You can accomplish this by including the CS_OWNDC flag as part of the window class style when you register the window class: wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ; yes, I want the DC attributes be saved and can be used later, but in my ActiveX Project, this doesn't work.My ActiveX Project is a Transparent control, i want save DC after draw something on DC in OnDraw function and can be used like this:// ...save DC before CDC *getDC = GetDCEx(cRgn, DCX_CACHE);// the use getDC draw current DC pdc->BitBlt(rcBounds.left, rcBounds.top, rcBounds.Width(), rcBounds.Height(), getDC, rcBounds.left, rcBounds.top, SRCCOPY);but the control disappeared, why?My english is poor, I wish somebody can understand.
  • 3. LoadImage for jpg-files
    Hi, I'm seeking the simplest way to load jpg-image with respective decompressing. I would like to recieve DIB as the result of this "LoadImage"-operation for the next manipulations with image's bits and for saving it in jpg-format. Does anybody know about such simple method (free sources)? Vladimir

Drawing DIBs considerations

Postby Wessam Bahnassi » Sat, 10 Sep 2005 03:58:42 GMT

Greetings guys!

Are there any special considerations with regards to dealing with DIBs?
(e.g. dimensions, stride alignment, bit depth).
I have a dib that I'm filling dynamically. However, when I'm drawing it, I
get garbage with certain dimension combos (e.g. 50x51) but for some other
dimensions it works (e.g. 100x100).

This is how I'm dealing with the DIB:

// Initialization...
int iSize = myWidth*myHeight*3; // RGB
BITMAPINFO *pBmp = (BITMAPINFO*)malloc(sizeof(BITMAPINFO)+iSize);
pBmp->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBmp->bmiHeader.biWidth = myWidth;
pBmp->bmiHeader.biHeight = -myHeight; // top-down image
pBmp->bmiHeader.biPlanes = 1;
pBmp->bmiHeader.biBitCount = 24;
pBmp->bmiHeader.biCompression = BI_RGB;
pBmp->bmiHeader.biSizeImage = 0;

// .. Fill pBmp->bmiColors with RGB data
// This is done by casting pBmp->bmiColors to a 3-byte struct
// and setting each pixel individually

// Draw it...
SetDIBitsToDevice(hDC,0,0,myWidth,myHeight,0,0,0,myHeight,pBmp->bmiColors,pBmp,DIB_RGB_COLORS);




Re: Drawing DIBs considerations

Postby Michael Phillips, Jr. » Sat, 10 Sep 2005 04:25:44 GMT

For bitmaps with bit depths greater than 1bpp, the scanline
must be aligned on a DWORD boundary.

"Wessam Bahnassi" < XXXX@XXXXX.COM > wrote in 





Re: Drawing DIBs considerations

Postby Kellie Fitton » Sat, 10 Sep 2005 04:44:46 GMT

Hi,

Well, when using the API's GetDIBits(), SetDIBits(), it is important
to handle the alignment of the DIB data, the DIB data are always
full DWORD aligned, so you need to pad each scanLine out to a full
DWORD boundary.

Total surface bytes = Y Resolution * DWORD aligned X Resolution

 http://www.**--****.com/ 

 http://www.**--****.com/ 

 http://www.**--****.com/ 

Hope these information helps,

Kellie.



Return to Win32 Programming

 

Who is online

Users browsing this forum: No registered users and 18 guest