|
[Visual Basic]
Dim bg As New Canvas
Dim stamp As New Canvas
Dim mask As New Canvas
' create canvas
bg.Color = System.Drawing.Color.Blue
bg.Width = 100
bg.Height = 90
mask.DrawFile(Server.MapPath("rez/cloud.gif"), "")
stamp.Width = mask.Width
stamp.Height = mask.Height
' first draw white cloud
stamp.Color = System.Drawing.Color.White
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=10,10 Mode=Transparent")
' ... then light gray cloud
stamp.Color = System.Drawing.Color.LightGray
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=60,10 Mode=Transparent")
' ... then dark gray cloud
stamp.Color = System.Drawing.Color.Gray
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=10,60 Mode=Transparent")
' ... then black cloud
stamp.Color = System.Drawing.Color.Black
stamp.Erase()
stamp.SetChannel("alpha", mask.Image)
bg.DrawCanvas(stamp.Image, "Pos=60,60 Mode=Transparent")
' finally save image
bg.SaveAs(Server.MapPath("setchannel.jpg"), "Quality=high")
[C#]
Canvas bg = new Canvas();
Canvas stamp = new Canvas();
Canvas mask = new Canvas();
// create canvas;
bg.Color = System.Drawing.Color.Blue;
bg.Width = 100;
bg.Height = 90;
mask.DrawFile(Server.MapPath("rez/cloud.gif"), "");
stamp.Width = mask.Width;
stamp.Height = mask.Height;
// first draw white cloud;
stamp.Color = System.Drawing.Color.White;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=10,10 Mode=Transparent");
// ... then light gray cloud;
stamp.Color = System.Drawing.Color.LightGray;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=60,10 Mode=Transparent");
// ... then dark gray cloud;
stamp.Color = System.Drawing.Color.Gray;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=10,60 Mode=Transparent");
// ... then black cloud;
stamp.Color = System.Drawing.Color.Black;
stamp.Erase();
stamp.SetChannel("alpha", mask.Image);
bg.DrawCanvas(stamp.Image, "Pos=60,60 Mode=Transparent");
// finally save image;
bg.SaveAs(Server.MapPath("setchannel.jpg"), "Quality=high");
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
setchannel.jpg
|
|
|