Sets the palette of this
RasterImage object.
Supported in Silverlight, Windows Phone 7
Syntax
Visual Basic (Usage) | Copy Code |
---|
Dim instance As RasterImage
Dim palette() As RasterColor
Dim startIndex As Integer
Dim count As Integer
instance.SetPalette(palette, startIndex, count) |
Parameters
- palette
- An array of RasterColor containing the new palette to use.
- startIndex
- Index of the first palette entry to replace.
- count
- Number of palette entries to replace.
Example
Visual Basic | Copy Code |
---|
Public Sub PaletteExample()
Dim codecs As RasterCodecs = New RasterCodecs()
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RedPalette.bmp")
' Load the image as 8 bits/pixel
Dim image As RasterImage = codecs.Load(srcFileName, 8, CodecsLoadByteOrder.Rgb, 1, 1)
' Get the palette of this image and change it to shades of red
Dim palette As RasterColor() = image.GetPalette()
Dim i As Integer = 0
Do While i < palette.Length
palette(i) = New RasterColor(i, 0, 0)
i += 1
Loop
' Set the palette back in the image then save the file
image.SetPalette(palette, 0, palette.Length)
codecs.Save(image, destFileName, RasterImageFormat.Bmp, image.BitsPerPixel)
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class |
C# | Copy Code |
---|
public void PaletteExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir,"Image1_RedPalette.bmp");
// Load the image as 8 bits/pixel
RasterImage image = codecs.Load(srcFileName, 8, CodecsLoadByteOrder.Rgb, 1, 1);
// Get the palette of this image and change it to shades of red
RasterColor[] palette = image.GetPalette();
for(int i = 0; i < palette.Length; i++)
palette[i] = new RasterColor(i, 0, 0);
// Set the palette back in the image then save the file
image.SetPalette(palette, 0, palette.Length);
codecs.Save(image, destFileName, RasterImageFormat.Bmp, image.BitsPerPixel);
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
} |
SilverlightCSharp | Copy Code |
---|
public void PaletteExample(RasterImage image, Stream destStream)
{
// image should be loaded as 8 bits/pixel
// Get the palette of this image and change it to shades of red
RasterColor[] palette = image.GetPalette();
for (int i = 0; i < palette.Length; i++)
palette[i] = new RasterColor(i, 0, 0);
// Set the palette back in the image then save the file
image.SetPalette(palette, 0, palette.Length);
RasterCodecs codecs = new RasterCodecs();
codecs.Save(image, destStream, RasterImageFormat.Bmp, 0);
image.Dispose();
} |
SilverlightVB | Copy Code |
---|
Public Sub PaletteExample(ByVal image As RasterImage, ByVal destStream As Stream)
' image should be loaded as 8 bits/pixel
' Get the palette of this image and change it to shades of red
Dim palette As RasterColor() = image.GetPalette()
Dim i As Integer = 0
Do While i < palette.Length
palette(i) = New RasterColor(i, 0, 0)
i += 1
Loop
' Set the palette back in the image then save the file
image.SetPalette(palette, 0, palette.Length)
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, destStream, RasterImageFormat.Bmp, 0)
image.Dispose()
End Sub |
Remarks
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