LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
RasterColor Structure
See Also  Members   Example
Leadtools Namespace : RasterColor Structure



Describes a color consisting of relative intensities of alpha, red, green, and blue. Supported in Silverlight, Windows Phone 7

Object Model

RasterColor Structure

Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Structure RasterColor 
   Inherits System.ValueType
Visual Basic (Usage)Copy Code
Dim instance As RasterColor
C# 
[SerializableAttribute()]
public struct RasterColor : System.ValueType 
C++/CLI 
[SerializableAttribute()]
public value class RasterColor : public System.ValueType 

Example

Converts a .NET color to a RasterColor and back.

Visual BasicCopy Code
Public Sub Example()
   ' Create a RasterColor
   Dim clr As New RasterColor(128, 24, 87, 134)

   ' Make sure the color is correct
   Debug.Assert(clr.A = 128)
   Debug.Assert(clr.R = 24)
   Debug.Assert(clr.G = 87)
   Debug.Assert(clr.B = 134)

   ' Show its value
   Console.WriteLine(clr)

   ' Show the A, R, G and B values
   Console.WriteLine("Alpha value: " + clr.A.ToString())
   Console.WriteLine("Red value: " + clr.R.ToString())
   Console.WriteLine("Green value: " + clr.G.ToString())
   Console.WriteLine("Blue value: " + clr.B.ToString())
End Sub
C#Copy Code
public void Example()
{
   // Create a RasterColor
   RasterColor clr = new RasterColor(128, 24, 87, 134);

   // Make sure the color is correct
   Debug.Assert(clr.A == 128);
   Debug.Assert(clr.R == 24);
   Debug.Assert(clr.G == 87);
   Debug.Assert(clr.B == 134);

   // Show its value
   Console.WriteLine(clr);

   // Show the A, R, G and B values
   Console.WriteLine("Alpha value: " + clr.A);
   Console.WriteLine("Red value: " + clr.R);
   Console.WriteLine("Green value: " + clr.G);
   Console.WriteLine("Blue value: " + clr.B);
}
SilverlightCSharpCopy Code
[TestMethod]
public void Example()
{
   Random rand = new Random();
   // Create a random .NET color
   Color clr1 = Color.FromArgb((byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256));

   // Convert this color to a LEADTOOLS color
   RasterColor clr2 = RasterColorConverter.FromColor(clr1);

   // Make sure both colors are equal
   Debug.Assert(clr1.A == clr2.A);
   Debug.Assert(clr1.R == clr2.R);
   Debug.Assert(clr1.G == clr2.G);
   Debug.Assert(clr1.B == clr2.B);

   // Convert the LEADTOOLS color back to .NET
   clr1 = RasterColorConverter.ToColor(clr2);

   // Make sure both colors are equal
   Debug.Assert(clr1.A == clr2.A);
   Debug.Assert(clr1.R == clr2.R);
   Debug.Assert(clr1.G == clr2.G);
   Debug.Assert(clr1.B == clr2.B);
}
SilverlightVBCopy Code
<TestMethod> _
Public Sub Example()
   Dim rand As Random = New Random()
   ' Create a random .NET color
   Dim clr1 As Color = Color.FromArgb(CByte(rand.Next(256)), CByte(rand.Next(256)), CByte(rand.Next(256)), CByte(rand.Next(256)))

   ' Convert this color to a LEADTOOLS color
   Dim clr2 As RasterColor = RasterColorConverter.FromColor(clr1)

   ' Make sure both colors are equal
   Debug.Assert(clr1.A = clr2.A)
   Debug.Assert(clr1.R = clr2.R)
   Debug.Assert(clr1.G = clr2.G)
   Debug.Assert(clr1.B = clr2.B)

   ' Convert the LEADTOOLS color back to .NET
   clr1 = RasterColorConverter.ToColor(clr2)

   ' Make sure both colors are equal
   Debug.Assert(clr1.A = clr2.A)
   Debug.Assert(clr1.R = clr2.R)
   Debug.Assert(clr1.G = clr2.G)
   Debug.Assert(clr1.B = clr2.B)
End Sub

Remarks

The LEADTOOLS RasterColor class provides a platform independent representation of an ARGB color that can be used in any platform supported by LEADTOOLS such as GDI, GDI+, WPF and Silverlight.

To convert a LEADTOOLS RasterColor object to/from a device dependent color, you can either use the various properties of methods of this class (such as the A, R, B, B properties and the RasterColor(int alpha, int red, int green, int blue) constructor) directly, or use the following helper classes:

Inheritance Hierarchy

System.Object
   System.ValueType
      Leadtools.RasterColor

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also