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!"


VC++ GDI Example: GDI AlphaBlend  and Bitmap Alpha

 
 

Introduction

This article shows how the GDI function AlphaBlend is used to display and overlay 32 bit bitmaps with an alpha channel. It is mainly a hint, which would have saved me hours of research.

Code Snippet

Collapse Copy Code
// the blending of the bitmap is quite simple
// (in the OnPaint() method or the WM_PAINT message handler: 
BITMAP bm;
GetObject(background, sizeof(BITMAP), &bm);
AlphaBlend(hdcMemWork, 0,0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, 
           bm.bmWidth, bm.bmHeight, blendFkt)
SelectObject(hdcMem, hbmOld);

// The tricky thing is to pre multiply the alpha channel
// values after loading the 32 bit bitmaps
if(bmInfo.bmiHeader.biBitCount == 32 )
// Alpha Channel
{
    // pre-multiply rgb channels with alpha channel
    for (int y=0; y<bmInfo.bmiHeader.biHeight; ++y)
    {
        BYTE *pPixel= (BYTE *) lpDIBBits + bmInfo.bmiHeader.biWidth * 4 * y;
        for (int x=0; x<bmInfo.bmiHeader.biWidth ; ++x)
        {
            pPixel[0]= pPixel[0]*pPixel[3]/255;
            pPixel[1]= pPixel[1]*pPixel[3]/255;
            pPixel[2]= pPixel[2]*pPixel[3]/255;
            pPixel+= 4;
        }
    }
}

Points of interest

I played around a long time until AlphaBlend began working. At least the trick was to pre multiply the color values of the bitmap with the alpha value. Then, everything worked fine. Be careful with the width and height you provide to AlphaBlend(). If this exceeds the bounds of the bitmap, nothing is displayed. I prefer getting the width and height directly out of the bitmap data as shown.

 

 

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