|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
[Using the demo project, you can insert any image and control the transparency of the image, and you can even save the final image as a different file. You can also select a base image to serve as the background image over which you can insert images. But you cannot control the transparency of the base image. For selecting the base image, choose File->Open Base Image menu and select the desired image. For inserting the image, choose Insert->Image menu item and select the image.]
IntroductionAlpha blending allows two objects to be visually blended together. This is primarily used for 3D atmospheric and environmental effects. It allows such things as "fogging", where an image is rendered behind another translucent image, which creates the effect of looking though fog or looking down through a pool and seeing the bottom. It also allows Depth Cueing, which is the lowering of the intensity of lighting to make an object appear farther away. In computer graphics, each pixel has three channels of color information--red, green, and blue--and sometimes a fourth called the alpha channel. This fourth channel controls the way in which other graphics information is displayed, such as levels of transparency or opacity. Alpha blending is the name for this type of control, and it's used to simulate effects such as placing a piece of glass in front of an object so that the object is completely visible behind the glass, un-viewable, or something in between.
Figure1: Alpha blending process Alpha blending can be done in per pixel basis or for the entire image. In per pixel basis alpha blending, each pixel should contain the alpha component and the transparency of each pixel is controlled by this value. When we do alpha blending for the entire image, the same alpha component will be used for the entire image and hence the transparency of all pixels in the image will be the same. Alpha blending using GDI+Step 1: Loading the desired imagesWe can easily construct an image object from an image file using the powerful Image img1("Flower1.jpg");
Image img2("Flower2.jpg");
The So, the next step is to initialize a color matrix object and pass it to the appropriate method of an Step 2: Creating the ImageAttributes and ColorMatrix objectsA color matrix is a matrix that contains values for channels. It's a 5x5 matrix which represents values for the Red, Green, Blue, Alpha channels and another element w, in that order (RGBAw). In a What you have to do is to create a new ColorMatrix ClrMatrix = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
The 0.5f value in the above code represents the alpha blend value. 0.5 means semi transparent (50%). Once you initialize the ImageAttributes ImgAttr;
ImgAttr.SetColorMatrix(&ClrMatrix, ColorMatrixFlagsDefault,
ColorAdjustTypeBitmap);
The final step is to draw the original image with the Step 3: Alpha blending the imagesAs we need to blend g.DrawImage(&img1, 0,0,img1.Width,img1.Height);
To alpha blend image g.DrawImage(&img2, RectF destination(0,0, img2.Width,img2.Height), 0,0,
img2.Width,img2.Height,UnitPixel,&ImgAttr);
Now the resultant image on the (The HistoryDate posted: March 06, 2005.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||