free web hosting | website hosting | Business Hosting | Free Website Submission | shopping cart | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
AlhpaBlend -- Misty Background

AlhpaBlend -- Misty Background

Reduced Alpha Values

To place emphasis on every items in the picture will not make things clear. To clarify the specific objectives and shut off noisy background, the background need to be toned down. This page explains how to soften the background color by reducing alpha values. With small alpha value, the image will appear foggy and misty.

Alpha value specifies the degree to which the pixel color values will appear. The value ranges from 0 to 0xff (255) and with 0xff value, the pixel will appear in full color value. In the AlphaBlend function, supply BLENDFUNCTION structure to specify the alpha value.

The following code below shows how to draw the given image with the specified alpha value. It takes the pointer to CDC where the image will be drawn, the pointer to CImage class of the image to be drawn, and the alpha value. The function creates CDC class of the image, clears the background, set the BLENDFUNCTION value, and draw the image with the specified alpha value with CDC::AlphaBlend function. The CDC needs to be released before the image is destroyed.


   void CPhotoDialog::DrawOpaque(CDC* pDC, CImage* pImage, int alpha)
   {
	CDC *pImageDC=CDC::FromHandle(pImage->GetDC());

	int imageWidth=pImage->GetWidth();
	int imageHeight=pImage->GetHeight();

	CBrush brush(RGB(255,255,255));
	pDC->FillRect(CRect(0,0,imageWidth,imageHeight),&brush);

	BLENDFUNCTION bf;
	bf.AlphaFormat = 0;
	bf.BlendFlags = 0;
	bf.BlendOp = AC_SRC_OVER;
	bf.SourceConstantAlpha = alpha;

	pDC->AlphaBlend(0, 0, imageWidth, imageHeight, pImageDC, 0, 0, imageWidth, imageHeight, bf);

	pImage->ReleaseDC();
   }


Return to Home Page
Erica Asai
Last Modified: Sun Sep 03 06:23:09 2006