|
|
This allows you to insert an alpha channel using either a
constant value or another image as a matte.
If you pass an image matte and the sizes of the two images do
not match the intensity map will be stretched to the correct
size.
Passing a value sets the alpha channel to a constant value.
However if you intend to use a fully opaque value it is better to
remove the alpha channel as this is faster and simpler.
This allows you to insert an alpha channel using either a
constant value or another image as a matte.
If you pass an image matte and the sizes of the two images do
not match the intensity map will be stretched to the correct
size.
Passing a value sets the alpha channel to a constant value.
However if you intend to use a fully opaque value it is better to
remove the alpha channel as this is faster and simpler.
|
|
|
[C#]
using (Bitmap bm = new Bitmap(500, 500))
using (Bitmap mask = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/cloudmask.gif")))
using (Bitmap stamp = new Bitmap(mask.Width, mask.Height)) {
stamp.SetResolution(mask.HorizontalResolution, mask.VerticalResolution);
using (Graphics stampGraphics = Graphics.FromImage(stamp)) {
using (Graphics graphics = Graphics.FromImage(bm)) {
graphics.Clear(Color.Blue);
// first draw white cloud;
stampGraphics.Clear(Color.White);
Effects.SetAlpha(stamp, mask);
graphics.DrawImageUnscaled(stamp, new Point(50, 50));
// ... then light gray cloud;
stampGraphics.Clear(Color.LightGray);
Effects.SetAlpha(stamp, mask);
graphics.DrawImageUnscaled(stamp, new Point(300, 50));
// ... then dark gray cloud;
stampGraphics.Clear(Color.Gray);
Effects.SetAlpha(stamp, mask);
graphics.DrawImageUnscaled(stamp, new Point(50, 300));
// ... then black cloud;
stampGraphics.Clear(Color.Black);
Effects.SetAlpha(stamp, mask);
graphics.DrawImageUnscaled(stamp, new Point(300, 300));
}
}
// finally save image;
bm.Save(Server.MapPath("IG8_Effects_SetAlpha.jpg"));
}
The above draws four solid blocks of color using an alpha
channel as a matte. The input and output files are shown below.

cloud.gif

IG8_Effects_SetAlpha.jpg
|