|
[Visual Basic]
Dim theObj As New Canvas
theObj.DrawFile(Server.MapPath("rez/boat.gif"), "")
' white transparent with a little tolerance
theObj.Select("notcolor", "keycolor=0xFF,0xFF,0xFF
tolerance=10.0")
theObj.SaveAs(Server.MapPath("alphaboat.png"), "alpha=true")
[C#]
Canvas theObj = new Canvas();
theObj.DrawFile(Server.MapPath("rez/boat.gif"), "");
// white transparent with a little tolerance;
theObj.Select("notcolor", "keycolor=0xFF,0xFF,0xFF
tolerance=10.0");
theObj.SaveAs(Server.MapPath("alphaboat.png"), "alpha=true");
The code above draws the image mypic onto a canvas. It then selects
everything that is white and saves the completed image with selection-as-alpha-channel
into a png. The input and output images are shown below.
boat.gif
alphaboat.png
[Visual Basic]
Dim ca1 As New Canvas
ca1.DrawFile(Server.MapPath("rez/boat.gif"), "")
' white transparent with a little tolerance
ca1.Select("notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0")
Dim ca2 As New Canvas
ca2.Color = System.Drawing.Color.Red
ca2.Width = ca1.Width
ca2.Height = ca1.Height
ca2.DrawCanvas(ca1.Image, "Mode=Transparent")
ca2.SaveAs(Server.MapPath("redboat.jpg"), "")
[C#]
Canvas ca1 = new Canvas();
ca1.DrawFile(Server.MapPath("rez/boat.gif"), "");
// white transparent with a little tolerance;
ca1.Select("notcolor", "keycolor=0xFF,0xFF,0xFF tolerance=10.0");
Canvas ca2 = new Canvas();
ca2.Color = System.Drawing.Color.Red;
ca2.Width = ca1.Width;
ca2.Height = ca1.Height;
ca2.DrawCanvas(ca1.Image, "Mode=Transparent");
ca2.SaveAs(Server.MapPath("redboat.jpg"), "");
The code above selects all the white - or nearly white - pixels
in the image and replaces them with red ones before saving the final
output as a JPEG. The final output is shown below.
redboat.jpg
|