满堂花醉三千客 一剑霜寒四十州

AlphaBlendMatrix and how to resize the image by C#

In GDI+, a color is a 32-bit value with 8 bits each for alpha, red, green, and blue. The alpha value indicates the transparency of the color — the extent to which the color is blended with the background color. Alpha values range from 0 through 255, where 0 represents a fully transparent color, and 255 represents a fully opaque color.

Alpha blending is a pixel-by-pixel blending of source and background color data. Each of the three components (red, green, blue) of a given source color is blended with the corresponding component of the background color according to the following formula:

For example, suppose the red component of the source color is 150 and the red component of the background color is 100. If the alpha value is 200, the red component of the resultant color is calculated as follows:

150 × 200 / 255 + 100 × (255 – 200) / 255 = 139

Here I learned how to merge two images in C# and designed a simple program to show how it does.

Click on openfile button to select the image you want. It involves with a function named ResizeImage, and I would like to introduce this one later on.

Regard the right image as destImage, thus the left one is the srcImage.