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

setchannel.jpg
|