Sets the color channel using another image as an intensity map.
Syntax

[C#]

void SetChannel(string inChannel, Canvas inCanvas);
void SetChannel(string inChannel, XImage inImage);

[Visual Basic]

Sub SetChannel(inChannel As String, inCanvas As Canvas)
Sub SetChannel(inChannel As String, inImage As XImage)
Params
Name Description
inChannel The name of the channel.
inCanvas The canvas for the intensity map.
inImage The image for the intensity map.
Notes

This allows you to insert a color channel using another image as an intensity map. Most commonly you will want to use this method to insert an alpha channel using another image as a matte. You can then use blends and transparencies (both are specified using alpha channels).

If the sizes of the two images do not match the intensity map will be stretched to the correct size.

The channel names you can use are:

  • red
  • green
  • blue
  • alpha

This operation is only valid for raster images so if the canvas is not raster based it will be rasterized.

See Also

Alpha Channels

Example

[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