YOU CAN CODE!

¡¡

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


MFC Sample: Changing Bitmaps Color Depth, CBitmap, GetDIBits

¡¡
By Gerd Esser
Environment:
MS VC++ 6.0

The basic problem of this code was to decrease a color depth of great bitmaps (like 8000 x 8000 pixels) to - for example - 4 bits per pixel and solving nearly (! see below) the original color palette. The first attempt was to use the method as shown in DDBtoDIB. But such great bitmaps produce an error: They do nothing sencefull in functions like GetDIBits. So I handle the bitmap in bands of smaller bitmap data and make direct file reading/saving operations of the bitmaps.

Because of the internal mapping of the color palette to the system palette I got some strange results. Also, by realizing the whole number of really used colors, I ve got another problem with the previous banding of the bitmap, which show me only a small part of the overall used colors. This was the second problem. So I create a color palette by counting and adding the colors of each band to a global color palette of the bitmap.

A small problem still remains: By mapping the source bitmap into memory, the color palette cannot be solved exactly. If the color palette cannot be mapped into the system palette, the result color palette may differ by a few percent. But I didn't spend more time to this fact because the present solution was sufficient for me.

The result is a class BitmapLib with two (static) methods, ChangeColorDepth() and GetUsedColors().

 

BOOL  CBitmapLib::ChangeColorDepth( CString const & stSrcBitmapFile,
                                    CString const & stDstBitmapFile,
                                    WORD const      wDstBitCount,
                                    CProgressCtrl * pProgressCtrl = NULL );

ChangeColorDepth() changes a color depth of a file based bitmap and saves the result into a destination file. The operation is done by increasing or decreasing the bits per pixel through the whole range from 1 to 32 (thus converting also from device dependent into device independent or the way back). The progress control is only used if nescessary and showing the work progress (great bitmaps last a few seconds ...)

int CBitmapLib::GetUsedColors( CString const & stSrcBitmapFile,
                               RGBQUAD *       pColorTable,
                               WORD const      wMaxColorTableSize,
                               CProgressCtrl * pProgressCtrl = NULL );

int CBitmapLib::GetUsedColors( BITMAPINFO const * pBmi,
                               BYTE const *       pBits,
                               UINT const         nStartScanLine,
                               UINT const         nScanLines,
                               RGBQUAD *          pColorTable,
                               WORD const         wMaxColorTableSize,
                               WORD &             wUsedColors );

A byproduct of the operation ChangeColorDepth() is the method GetUsedColors(), which count the the really used colors and produces a color table of the used colors.

Both methods abort its operation, if the destination color depth is not sufficient enough for the number of used colors in the source bitmap. This means that you always must have a raw idea of the final color table result - you cannot convert any High/True color bitmap with an unlimited size of used colors down to a DIB! Therefore you will need some intelligent algorithm, which must be incorporated within the library.

Downloads

Download source (class implementation and header) - 6 Kb


¡¡

Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net

¡¡