Gets or sets the transparent color used when painting this image.
public Leadtools.RasterColor TransparentColor {get; set;}
Public Property TransparentColor As Leadtools.RasterColor
public Leadtools.RasterColor TransparentColor {get; set;}
@property (nonatomic, copy) LTRasterColor *transparentColor
public RasterColor getTransparentColor()
public void setTransparentColor(RasterColor value)
get_TransparentColor();
set_TransparentColor(value);
Object.defineProperty('TransparentColor');
public:
property Leadtools.RasterColor TransparentColor {
Leadtools.RasterColor get();
void set ( Leadtools.RasterColor );
}
The transparent color used when painting this image.
The TransparentColor of a RasterImage is used when the Transparent property value is set to true.
Note, transparent paint does not work with RasterPaintEngine.Gdi. For more information, refer to RasterPaintProperties.
If this RasterImage has a BitsPerPixel value of 8 or less, then the image has a palette. For palettized images, the value of the TransparentColor can be an RGB value or a palette index.
To set a palette index as the transparent color, use the RasterColor.FromPaletteIndex method.
If the color passed is a true RGB value(The value of see RasterColor.IsPaletteIndex is false and the image has a palette, then this RasterImage object will call GetTrueColorValue on the TransparentColor to translate it into the nearest palette index entry before using it to determine the actual transparent color in the image when painting.
For more information, refer to PNG Files and Transparency.
For an example of how to use this property when loading/saving images with transparent colors such as GIF, refer to GetTrueColorValue.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
using Leadtools.Drawing;
using Leadtools.Controls;
using LeadtoolsExamples.Common;
using Leadtools.Svg;
public void TransparentColorExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(ImagesPath.Path, "Ocr1.tif");
string destFileName = Path.Combine(ImagesPath.Path, "Ocr1_Transparent.gif");
// Load the image
RasterImage image = codecs.Load(srcFileName);
// Change the image's palette to be Red and Blue
RasterColor[] redBluePalette = new RasterColor[2];
redBluePalette[0] = RasterColor.FromKnownColor(RasterKnownColor.Red);
redBluePalette[1] = RasterColor.FromKnownColor(RasterKnownColor.Blue);
image.SetPalette(redBluePalette, 0, 2);
// make red the transparent color
image.Transparent = true;
image.TransparentColor = redBluePalette[0];
// Save the image
codecs.Save(image, destFileName, RasterImageFormat.Gif, 8);
// Now load Ocr1_Transparent.gif in Internet Explorer.
// Notice how red is treated as a transparent color.
// You should get Blue text on a white background
// (if IE's background color is white).
image.Dispose();
codecs.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg
Public Sub TransparentColorExample()
Dim codecs As RasterCodecs = New RasterCodecs()
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")
Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_Transparent.gif")
' Load the image
Dim image As RasterImage = codecs.Load(srcFileName)
' Change the image's palette to be Red and Blue
Dim redBluePalette As RasterColor() = New RasterColor(1) {}
redBluePalette(0) = RasterColor.FromKnownColor(RasterKnownColor.Red)
redBluePalette(1) = RasterColor.FromKnownColor(RasterKnownColor.Blue)
image.SetPalette(redBluePalette, 0, 2)
' make red the transparent color
image.Transparent = True
image.TransparentColor = redBluePalette(0)
' Save the image
codecs.Save(image, destFileName, RasterImageFormat.Gif, 8)
' Now load Ocr1_Transparent.gif in Internet Explorer.
' Notice how red is treated as a transparent color.
' You should get Blue text on a white background
' (if IE's background color is white).
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Dicom;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
using Leadtools.Windows.Media;
public void TransparentColorExample(RasterImage image, Stream destStream)
{
// Change the image's palette to be Red and Blue
RasterColor[] redBluePalette = new RasterColor[2];
redBluePalette[0] = RasterColorConverter.FromColor(Colors.Red);
redBluePalette[1] = RasterColorConverter.FromColor(Colors.Blue);
image.SetPalette(redBluePalette, 0, 2);
// make red the transparent color
image.Transparent = true;
image.TransparentColor = redBluePalette[0];
// Save the image
RasterCodecs codecs = new RasterCodecs();
codecs.Save(image, destStream, RasterImageFormat.Gif, 8);
// Now load Ocr1_Transparent.gif in Internet Explorer.
// Notice how red is treated as a transparent color.
// You should get Blue text on a white background
// (if IE's background color is white).
image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Dicom
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media
Public Sub TransparentColorExample(ByVal image As RasterImage, ByVal destStream As Stream)
' Change the image's palette to be Red and Blue
Dim redBluePalette As RasterColor() = New RasterColor(1) {}
redBluePalette(0) = RasterColorConverter.FromColor(Colors.Red)
redBluePalette(1) = RasterColorConverter.FromColor(Colors.Blue)
image.SetPalette(redBluePalette, 0, 2)
' make red the transparent color
image.Transparent = True
image.TransparentColor = redBluePalette(0)
' Save the image
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, destStream, RasterImageFormat.Gif, 8)
' Now load Ocr1_Transparent.gif in Internet Explorer.
' Notice how red is treated as a transparent color.
' You should get Blue text on a white background
' (if IE's background color is white).
image.Dispose()
End Sub
Products |
Support |
Feedback: TransparentColor Property - Leadtools |
Introduction |
Help Version 19.0.2017.6.19
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.