|

Preface
The sample demo workspace includes two projects: DIBSectionTest for Win32
environments, and DIBSectionTestCE for CE environments that demonstrate the DIBSection wrapper. You will need the CE SDKs from Microsoft to be installed before you can build DIBSectionTestCE.dsw.
There is also a version of the DIBSection wrapper ported by Kenny Goers with no dependancies on MFC. This version is currently slightly out of sync with the MFC version, and is provided as a convenience only.
Introduction
Device Independant Bitmaps (DIBs) offer a means to manipulate and display
bitmaps in a form that is independant of the current display setting of your
computer. They are also the format of the standard windows .BMP file, and so
having a means to load, display and modify DIBs is very handy.
Win32 offers many different ways of dealing with DIBs, including the standard
DIB functions such as SetDIBitsToDevice, GetDIBits etc,
the DrawDib functions, and the GDI functions such as BitBlt
for use with DIBsections.
However, when working in a CE environment, many of the usual functions we
know and love have been discarded in an effort to reduce the size of the overall
OS, and as such we are only left with the possibility of using DDB's (via CBitmap)
or DIBSections. This is not too much of a handycap though since DIBSections are,
in a way, superior to plain DIBs in that they have an associated HBITMAP handle,
and hence can be manipulated via the GDI functions such as BitBlt and StretchBlt.
Furthermore, the handle to a DIBSection can be selected into a memory DC and then
drawn to directly using the TextOut, Line etc GDI functions.
This is far easier than accessing the bits of a DIB yourself and plotting the pixels
one by one.
The only problem with DIBsections, from an MFC programmers point of view, is
that there is no DIBSection wrapper. Jeff Prosise, in his book Programming Windows
95 with MFC discusses DIBSections and how great they are, but states that because
the next version of MFC will have a DIBSection wrapper class, there is no
point in him supplying one in his book. Oops! Several updates to MFC have come and gone
since that book was written and still there is no sign of a DIBSection wrapper
class.
With the advent of CE, DIBSections have become even more important. Here I
present the CDIBSectionLite class - a DIBSection wrapper class for Win32
and WinCE platforms. This class provides a simple interface to DIBSections including
loading, saving and displaying DIBSections. Full palette support is provided for Win32
and CE 2.11 and above.
Note that CE introduces a new bitmap depth, namely 2 bits per pixel. This is for
older 4-level grey scale devices. CDIBSectionLite supports this pixel
depth in CE builds only.
Creating and displaying DIBSections
The first step in creating a DIBSection is to fill out a BITMAPINFOHEADER
structure. If you are creating a DIBSection from scratch then just fill in
these values with whatever you like. If, on the other hand, you wish to
convert a DDB to a DIBSection then your best friend is the GetDIBits function.
It fills in the BITMAPINFOHEADER structure for you by querying the values of
the supplied bitmap.
Unfortunately CE does not support this function and so you must do this yourself.
While this is no great drama it does make it a little more difficult to get the
colour table info from the supplied bitmap. Microsoft have kindly helped us programmers
along by writing the KB article HOWTO: Get the Color Table of a DIBSection in Windows
CE. One limitation of the code in the KB article is that it only extracts color
table info for bitmaps that are DIBSections themselves. CDIBSectionLite
gets around this by synthesizing a half-tone color table for DDB's without color
table info.
Once you have the BITMAPINFOHEADER structure, including the color table entries
filled in, simply call CreateDIBSection. This funtion will return a HBITMAP
handle plus a pointer to the actual image bits. What more could you ask for!
To actually display the DIBSections you simply use the tried and true windows
GDI functions (BitBlt etc). Some functionality is lost in CE, such as GDIFlush
and SetStretchBltMode, but on the whole a HBITMAP created as a DIBSection is no
different to use than a HBITMAP from a DDB.
The CDIBSectionLite class includes support for the DrawDib functions. These provide
high speed display as well as dithering, but unfortunately are not available on CE.
To toggle between using the windows GDI and the DrawDib routines, use the
CDIBSectionLite::SetDither(...) function.
Using CDIBSectionLite
This class is very simple to use and wraps all the messy plumbing from view.
The bitmap can be set using either SetBitmap() (which accepts either a Device
dependant or device independant bitmap, or a resource ID) or by using Load(),
which allows an image to be loaded from disk. To display the bitmap simply use
Draw or Stretch.
eg.
CDIBsectionLite dibsection;
dibsection.Load(_T("image.bmp"));
dibsection.Draw(pDC, CPoint(0,0));
CDIBsectionLite dibsection;
dibsection.SetBitmap(IDB_BITMAP);
dibsection.Draw(pDC, CPoint(0,0));
CDIBsectionLite API
The CDIBSectionLite API includes methods for loading and
displaying images, methods to extract information about the image, as well as
palette options for getting and setting the current palette. Note that the
palette methods are only available in Win32 or in CE 2.11 or later.
HBITMAP GetSafeHandle() const
operator HBITMAP() const
CSize GetSize() const
int GetHeight() const
int GetWidth() const
int GetPlanes() const
int GetBitCount() const
LPVOID GetDIBits()
LPBITMAPINFO GetBitmapInfo()
DWORD GetImageSize() const
LPBITMAPINFOHEADER GetBitmapInfoHeader()
LPRGBQUAD GetColorTable()
LPRGBQUAD GetColorTable()
BOOL SetColorTable(UINT nNumColors, RGBQUAD *pColors);
int GetColorTableSize()
CPalette *GetPalette();
BOOL SetPalette(CPalette* pPalette);
BOOL SetLogPalette(LOGPALETTE* pLogPalette);
BOOL SetBitmap(UINT nIDResource);
BOOL SetBitmap(LPCTSTR lpszResourceName);
BOOL SetBitmap(HBITMAP hBitmap, CPalette* pPalette = NULL);
BOOL SetBitmap(LPBITMAPINFO lpBitmapInfo, LPVOID lpBits);
BOOL Load(LPCTSTR lpszFileName);
BOOL Save(LPCTSTR lpszFileName);
BOOL Copy(CDIBSectionLite& Bitmap);
BOOL Draw(CDC* pDC, CPoint ptDest, BOOL bForceBackground = FALSE);
BOOL Stretch(CDC* pDC, CPoint ptDest, CSize size, BOOL bForceBackground = FALSE);
BOOL SetDither(BOOL bDither);
BOOL GetDither();
void DeleteObject()
Latest Updates
- 4 May 2000 - The class was updated with corrections from Jim Miller
of 3DFX to correct a bug with compressed bitmaps.
- 20 Sep 2000 - Fixed Bug fix in Save() (saving 4 bytes too many - Tadeusz Dracz)
Allowed lpBits to be NULL in SetBitmap - Don Grasberger
Fixed NumColorEntries bug - Itay Szekely
Fixed buffer overrun bug in Load() - Itay Szekely
- 5 Apr 2001 - Fix for 16/32 bpp bitmaps for PocketPC's (Dan Robbins)
Non-MFC port (Kenny Goers)
- 22 May 2001 - Fix for missing break in 24bpp case of NumColorEntries (Steve Kramp)
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 115 (Total in Forum: 115) (Refresh) | FirstPrevNext |
|
|
 |
|
|
I am doing calcualtion (scientific) that uses 2D arrays. These shall also be saved as Bitmaps (256 colors grayscale data). I wonder how I can convert my Array Data to a 'bitmap' usefull for dibsection.
Matthias Pospiech
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I need to be able to open more then one image at a time so that I can compare two images to try doing motion estimation. I seem to be able to bring up two open dialog boxes but nothing but can't seem to access the image data assuming I'm actually loading both images 2 memory
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
i would like to load a bitmap on Windows CE device. Loading and displaying works fine. Now, however, I have the problem that the picture is bigger than the main storage of my CE device. I must split the image in several parts, before loading it and allocates the memory. How can I realise this?
Thanks for help !
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
Can anyone tell me why I allways get ERROR_NOT_ENOUGH_MEMORY when I call GetLastError after CreateDIBSection?
thanks.
|
| Sign In·View Thread·PermaLink | 1.25/5 (3 votes) |
|
|
|
 |
|
|
hey Chris, great class. unfortunately the guy who put together the "non-mfc" version either put the wrong stuff into his zip file, posted the wrong zip file, or he half-ass it. the one that's currently posted is pretty much worthless without a lot of work.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The non-mfc version is a semi-manufactured goods, and has fatal errors. I have completed another one. If anybody wants it, contact me, dandycheung#21cn.com. By the way, all dithering stuff was removed also. If you want better drawing functionality, writing a separate drawing class is a good idea, I think.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
Hi Chris,
Is there a chance you'll write a wrapper for .Net compact framework ????
I'm asking you because I'm looking for ways to rotate images (to any angle) in Pocket PC using compact framework (The managed GetPixel/SetPixel is so slow that its useless).
Will you salvage me? 
Thanks,
Alon
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
your class just saved my hide. Im working on an eleventh hour demo and I needed to render a bitmap to a CE device. I know full well how to do in on desktop OS, but was lost on CE. Hooked up your class, and it worked perfectly. Only mod I made was below, as I didnt need to render the whole bitmap, just a viewport, so I added origin and size params as shown. Thanks You get my 5.
BOOL CDIBSectionLite::Draw(CDC* pDC, CPoint ptDest, BOOL bForceBackground /*=FALSE*/) { return Draw(pDC,ptDest,CPoint(0,0),GetSize(),bForceBackground); }
BOOL CDIBSectionLite::Draw(CDC* pDC, CPoint ptDest, CPoint ptOrigin, CSize size, BOOL bForceBackground /*=FALSE*/) { if (!m_hBitmap) return FALSE;
BOOL bResult = FALSE;
etc...
SGarratt
-- modified at 3:16 Thursday 1st September, 2005
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
My platform is Pocket PC 2003. And this code can display while the saved file has all white pixels. I don't know why, please help me.
void CTestView::OnDraw(CDC *pDC) { CTestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc);
// TODO: add draw code for native data here CRect rectClient; GetClientRect(&rectClient);
CBitmap bmp; bmp.CreateCompatibleBitmap(pDC, rectClient.Width(), rectClient.Height()); CDIBSectionLite dib; //dib.SetBitmap(IDB_BITMAP); CDC *pDCMem = dib.GetMemoryDC();
dib.SetBitmap((HBITMAP)bmp.GetSafeHandle());
CVOImage *pImg = pDoc->GetVOImage(); pImg->Load(pDCMem->GetSafeHdc(), _T("yao ming.jpg")); if (pImg->IsLoaded()) pImg->Draw(pDCMem->GetSafeHdc(), 0, 0);
pDC->BitBlt(0, 0, rectClient.Width(), rectClient.Height(), pDCMem, 0, 0, SRCCOPY);
dib.Save(_T("Yao ming.bmp")); }
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
I am having difficulty in converting 24 bit bitmap image to a grayscale image.I am knowing the Bitmap file format.Even then I am unable to do This. Please can you help me in this regard.
Sandeep
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Create a bitmap with a 256 greyscale color table and use the BitBlt function to transfer the image from the 24 bit bitmap. The operating system will automatically make the color conversions.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I am developing a DLL based on WinCE ATL Com AppWizard. In this DLL, i do have a button to save a hand-written signature(inside a rectangle) to a BMP file.
My question is: Can i use the above DIBSection wrapper for WinCE in my DLL? it seems like this wrapper only written for MFC, not ATL.
How about the non-MFC source? Is it 'suitable' for my ATL DLL? i downloaded the source, but the Save() function is not included. Is there anybody have this function written?
thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
hello,
in the method SetBitmap(LPBITMAPINFO lpBitmapInfo, LPVOID lpBits) there is a line:
DWORD dwBitmapInfoSize = sizeof(BITMAPINFO) + m_iColorTableSize *sizeof(RGBQUAD);
i guess it should be:
DWORD dwBitmapInfoSize = sizeof(BITMAPINFO) + (m_iColorTableSize - 1)*sizeof(RGBQUAD);
or :
DWORD dwBitmapInfoSize = lpBitmapInfo->bmiHeader.biSize + m_iColorTableSize *sizeof(RGBQUAD);
thanks for your code, bye
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
Hi,
Very nice piece of art thank you.
However, as I was looking at the code and in: GetColorTableEntries I found this sequence:
#ifndef _WIN32_WCE
#else
#ifdef _WIN32_WCE
#endif
#endif
What are the #ifdef #endif underlined are for?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have a challenge on Pocket PC where we have a 10,000 by 10,000 pixel image..or sometimes larger. We wish to use this bitmap as a database, where requests come into a component to load an imagine starting at pixel x to pixel y. Basically, we want to create a ROI (Region of Interest) bitmap without having to load the entire imagine into memory. I can imagine simply opening up a bitmap in binary file mode, seeking to a particular byte and then begin to filter the data into another file. Has anyone accomplished this? Does anyone know of any code out there that would solve our issue? Any help would be greatly appreciated!!!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
hi daer Sir i am a medium c++ programmer i have your problem just now! i like to know if you have overcome that problem or not please inform me about that also i am very interested in knowing that if you are overcomed is this method real time for viewing big pictures on pc screen or not. thanking you in advance my mail is shirin1383f@yahoo.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello
Well in my function i am drawing some content to my device context. Both the CMemDC (Device Context) and the CBitmap -> which was in the function called as CreateCompatibleDC() & CreateCompatibleBitmap() respectively
I get good results, with MemDC. As i am doing StretchBlt just after my complete drawing is done on the ClientDC , so that it is quite visible on the View.
Even on redraw i am calling the MemDC to strecthBlt and it works fine.
BUT
In my save as BMP function (called by the menu clicking). (Here i am using CDibSectionLite Class ) I am passing the handle of the CBitmap (mentioned above), as it is global. But what i get is the black screen.
Following is the code Filename = dlgFile.GetFileName (); CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_Bmp.m_hObject; dib.SetBitmap (hnd); dib.Save(Filename); m_Bmp.DeleteObject ();
What can be the reason and how to recover this. better if you can correct me
Leave your mark wherever you go
|
| Sign In·View Thread·PermaLink | 1.75/5 (3 votes) |
|
|
|
 |
|
|
I'm attempting to do a screen capture on a computer with only 256 colors. the code works works, except I'm getting different colors in my .bmp than are shown on the screen. I guessing that the palette isn't being created or realized correctly, but it looks to me like everything should be working.
Can anyone provide the magic line I'm missing to get the colors to show up correctly in my BMP?
code>>
CWnd * pDesktop = GetDesktopWindow(); CRect r; pDesktop->GetWindowRect(&r);
CDC * displayDC = new CDC(); HDC hdc = ::GetWindowDC(NULL); displayDC->Attach(hdc);
CDC * bitmapDC = new CDC(); bitmapDC->CreateCompatibleDC(displayDC); CBitmap a; a.CreateCompatibleBitmap(displayDC, r.Width(), r.Height()); CBitmap * oldBitmap = bitmapDC->SelectObject(&a); bool bResult = bitmapDC->BitBlt(0,0,r.Width(),r.Height(), displayDC, r.left, r.top, SRCCOPY); bitmapDC->SelectObject(oldBitmap); bitmapDC->DeleteDC(); delete bitmapDC; displayDC->DeleteDC(); delete displayDC;
CDIBSectionLite * pDib = new CDIBSectionLite(); pDib->SetBitmap((HBITMAP) a.m_hObject); pDib->Save("c:\\temp.bmp"); delete pDib;
thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have an application written in VC++ which prints lines, text and .BMP images to the screen and printer. The .BMP images look fine on screen and colour printers. They also convert nicely to a greyscale image on Hp5000, HP5 in windows XP. However in WIndows 2000 they do not convert nicely to greyscale on the HP5 although they are fine on the HP 5000. I use StretchBlt to move the bitmap into the output DC.
Regards Chris Ringrow chris.ringrow@i2i-solutions.net
Chris Ringrow
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
hi everybody, I am working with eMbedded VC++3.0 with HPC 2000 SDK . I met some problems when i tried to run the program.
Compiling resources... Compiling... DIBSectionLite.cpp C:\DIBSection_wrapper\DIBSection_demo\DIBSectionLite.cpp(35) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory DIBSectionTest.cpp C:\DIBSection_wrapper\DIBSection_demo\DIBSectionTest.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory DIBSectionTestDoc.cpp C:\DIBSection_wrapper\DIBSection_demo\DIBSectionTestDoc.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory DIBSectionTestView.cpp C:\DIBSection_wrapper\DIBSection_demo\DIBSectionTestView.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory MainFrm.cpp C:\DIBSection_wrapper\DIBSection_demo\MainFrm.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory StdAfx.cpp C:\DIBSection_wrapper\DIBSection_demo\StdAfx.cpp(5) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory Generating Code... Error executing clmips.exe.
DIBSectionTestCE.exe - 6 error(s), 0 warning(s)
Any method to solve it? thank you very much.
vincent sim5) : fatal error C1083: Cannot open precompiled header file: 'WMIPSDbg/DIBSectionTestCE.pch': No such file or directory Generating Code... Error executing clmips.exe.
DIBSectionTestCE.exe - 6 error(s), 0 warning(s)
Any method to solve it? thank you very much.
vincent sim
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Looks like your project is looking for pre-compiled headers. I haven't worked with eMbedded VC++3.0 for a long time, but this usually means (in MS-VC++6.0) that you have to change the precompiled header options.
Try rebuilding your project. If that doesn't work, then somewhere under the project settings choose automatic-use of precompiled headers or no-use of precompiled headers.
Just my $0.02, Adi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I am using following code for dispalying the recived buffer, But i genertaes access violation on SetBitmap function.
OnReceive(const LPBYTE lpBuffer, DWORD dwCount) { AfxMessageBox("Data Received"); // void *vPtr = malloc(dwCount + 1); CDIBSectionLite dibcli; LPBYTE mybuffer = lpBuffer;
// Display the received data // //memcpy(vPtr,lpBuffer,dwCount); //memcpy(mybuffer,vPtr,dwCount); dibcli.SetBitmap((BITMAPINFO *)mybuffer,(LPBYTE)mybuffer+sizeof(BITMAPINFO)); dibcli.Draw(m_Dlg->GetDC(),CPoint(0,0)); }
On debugging I found out that it is generating error on // Only copy bits if they were provided if (lpBits != NULL) memcpy(m_ppvBits, lpBits, m_DIBinfo.bmiHeader.biSizeImage);
statement. Can someone tell me what could be the reason for that?
Regards
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|