LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

TransparentColorプロパティ








このimageを描画するとき、使われる透明なカラーを取得または設定します。
構文
public RasterColor TransparentColor {get; set;}
'Declaration
 
Public Property TransparentColor As RasterColor
'Usage
 
Dim instance As RasterImage
Dim value As RasterColor
 
instance.TransparentColor = value
 
value = instance.TransparentColor
public RasterColor TransparentColor {get; set;}
@property (nonatomic, copy) LTRasterColor *transparentColor
public RasterColor getTransparentColor()
public void setTransparentColor(RasterColor value)
            
 <br/>get_TransparentColor();<br/>set_TransparentColor(value);<br/>Object.defineProperty('TransparentColor'); 
public:
property RasterColor TransparentColor {
   RasterColor get();
   void set (    RasterColor value);
}

属性値

このimageを描画するとき、使われる透明なカラー。
解説

Transparent属性値がtrueに設定されるとき、RasterImageTransparentColorが使われます。

透明な描画がRasterPaintEngine.Gdiで機能しないことに注意すべきです。詳細については、「RasterPaintProperties」を参照してください。

このRasterImageが8以下のBitsPerPixel値を持っているならば、imageはパレットを持っています。パレットイメージのために、TransparentColorの値は、RGB値またはパレットインデックスでありえます。

透明なカラーとしてパレットインデックスを設定するために、RasterColor.FromPaletteIndexメソッドを使います。

カラーが渡したかどうかはtrue RGB値です(値、RasterColor.IsPaletteIndexfalseである、そして、imageがパレットを持っていることを確かめます、そして、このRasterImageオブジェクトは描画するとき、imageで実際の透明なカラーを決定するためにそれを使う前に最も近いパレットインデックスエントリにそれを変換するためにTransparentColorの上でGetTrueColorValueを呼び出します。

詳細については、「PNGファイルと透明度」を参照してください。

サンプル

GIFなどの透明な色でイメージをロードして/保存するとき、どのようにこのプロパティを使うべきかのサンプルについては、「GetTrueColorValue」を参照してください。

Copy Code  
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.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(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();
}
RasterImageExamples.prototype.TransparentColorExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\Ocr1.tif";
         var destFileName = "Ocr1_Transparent.gif";
         var image;
         // Load the image
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
            .then(function (img) {
               image = img;
               // Change the image's palette to be Red and Blue
               var redBluePalette = [RasterColorHelper.fromKnownColor(RasterKnownColor.Red),
                  RasterColorHelper.fromKnownColor(RasterKnownColor.Blue)];
               image.setPalette(redBluePalette, 0, 2);

               // make red the transparent color
               image.transparent = true;
               image.transparentColor = redBluePalette[0];

               // Save the image
               return Tools.AppLocalFolder().createFileAsync(destFileName)
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create (saveFile);
               return codecs.saveAsync(image, saveStream, RasterImageFormat.gif, 8)
            })
            .then(function () {

               // 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.close();
               codecs.close();
            })
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;

      
public async Task TransparentColorExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Ocr1.tif";
   string destFileName = @"Ocr1_Transparent.gif";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Change the image's palette to be Red and Blue
   RasterColor[] redBluePalette = { RasterColorHelper.FromKnownColor(RasterKnownColor.Red),
                                    RasterColorHelper.FromKnownColor(RasterKnownColor.Blue)};
   image.SetPalette(redBluePalette, 0, 2);

   // make red the transparent color
   image.Transparent = true;
   image.TransparentColor = redBluePalette[0];

   // Save the image
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, 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();
}
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
必要条件

ターゲットプラットホーム

参照

参照

RasterImageクラス
RasterImageメンバ