←Select platform

Transparent Property

Summary
Gets or sets a value that indicates whether to use the transparent color.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool Transparent { get; set; } 
@property (nonatomic, assign) BOOL isTransparent 
public boolean getTransparentColor(); 
public void setTransparent( 
   boolean booleanValue 
); 
public: 
property bool Transparent { 
   bool get(); 
   void set (    bool ); 
} 
Transparent # get and set (RasterImage) 

Property Value

true to use the transparent color; false, otherwise.

Remarks

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.

For more information, refer to PNG Files and Transparency.

Example
C#
Java
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 Leadtools.Svg; 
 
 
public void TransparentColorExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "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(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.ArrayList; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.*; 
import leadtools.svg.*; 
import leadtools.imageprocessing.CloneCommand; 
import leadtools.imageprocessing.FillCommand; 
import leadtools.imageprocessing.FlipCommand; 
import leadtools.imageprocessing.GrayscaleCommand; 
import leadtools.imageprocessing.color.InvertCommand; 
import leadtools.imageprocessing.color.PosterizeCommand; 
 
 
public void transparentColorExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Ocr1.tif"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "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); 
   assertTrue(redBluePalette[0].equals(RasterColor.fromKnownColor(RasterKnownColor.RED))); 
 
   // Make red the transparent color 
   image.setTransparent(true); 
   image.setTransparentColor(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). 
 
   // Clean up 
   image.dispose(); 
   codecs.dispose(); 
 
   assertTrue("file unsuccessfully saved to " + destFileName, (new File(destFileName)).exists()); 
   System.out.printf("File saved successfully to %s%n", destFileName); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.