THotPDF.AddImageWithSMask メソッド

 

THotPDF.AddImageWithSMask

THotPDF

 

トップへ  前へ  次へ

カラー画像 XObject と PDF 1.4 のソフトマスク画像 XObject(ISO 32000-1 8.9.5.4)を一緒に追加します。結果の画像は、従来の /ImageMask 経路のような二値のオン/オフではなく、ピクセルごとの完全な透過度を持ちます

 

Delphi 構文:

function AddImageWithSMask(Width, Height: Integer; const RGB: array of Byte; const Alpha: array of Byte): Integer;

function AddImageWithTransparency(Width, Height: Integer; const RGB: array of Byte; const Alpha: array of Byte): Integer;

function AddImageWithSMask32(Width, Height: Integer; const Pixels: array of Byte): Integer;

function AddImageWithTransparency32(Width, Height: Integer; const Pixels: array of Byte): Integer;

 

C++ 構文:

int AddImageWithSMask(int Width, int Height, const TBytes& RGB, const TBytes& Alpha);

int AddImageWithTransparency(int Width, int Height, const TBytes& RGB, const TBytes& Alpha);

int AddImageWithSMask32(int Width, int Height, const TBytes& Pixels);

int AddImageWithTransparency32(int Width, int Height, const TBytes& Pixels);

 

説明

SMask 画像は独立した 8 ビット DeviceGray チャンネルを持ち、その輝度が描画時にカラー画像のアルファを駆動します(0 = 完全に透明、255 = 完全に不透明)。HotPDF は両方のプレーンを Flate 圧縮の画像 XObject として出力し、カラー画像ディクショナリーの /SMask エントリーをソフトマスク XObject へ配線し、THPDFPage.ShowImage がそのまま受け付ける XImages インデックスを返します。下流の配置コードは何も変えずにそのまま動きます

AddImageWithTransparency と AddImageWithTransparency32 は、同じ PDF 1.4 ソフトマスクワークフローの別名です。PDF のディクショナリー用語よりも透過画像という考え方で書かれた呼び出し側のために用意されています

 

AddImageWithSMask(Width, Height, RGB, Alpha)

- Width / Height: ピクセル寸法です。両方のプレーンで同一です

- RGB: Width * Height * 3 バイト。行優先・上から下で、ピクセルごとに R G B がインターリーブされます(行のパディングなし)

- Alpha: Width * Height バイト。行優先・上から下で、ピクセルごとに 8 ビットの輝度を持ちます

 

AddImageWithSMask32(Width, Height, Pixels)

パックされた 32 ビット RGBA 入力向けの簡易オーバーロードです。Pixels には R, G, B, A の順で Width * Height * 4 バイトが入っている必要があります。HotPDF はバッファーを RGB カラープレーンと 8 ビットのアルファプレーンに分割してから AddImageWithSMask へ処理を委ねます

 

戻り値: AddImage が返すのと同じ XImages のインデックスです。THPDFPage.ShowImage に渡すと画像をページへ配置できます。StrictVersionLock が有効で、アクティブな Version が PDF 1.4 未満の場合は -1 を返します(それ以外はバージョンが 1.4 へ自動的に引き上がります)

 

コード例

// 生バイトの経路:64x64 の白地にマゼンタの平面と水平方向の
// アルファグラデーションを組み立て、結果をページへ配置します
var
  RGB, Alpha: TBytes;
  W, H, X, Y, Idx, ImIdx: Integer;
begin
  W := 64;
  H := 64;
  SetLength(RGB,   W * H * 3);
  SetLength(Alpha, W * H);
  for Y := 0 to H - 1 do
    for X := 0 to W - 1 do
    begin
      Idx := Y * W + X;
      RGB[Idx * 3 + 0] := 255;    // R
      RGB[Idx * 3 + 1] := 0;      // G
      RGB[Idx * 3 + 2] := 255;    // B
      Alpha[Idx]       := Byte((X * 255) div (W - 1));
    end;

  HPDF.Version    := pdf14;       // SMask には PDF 1.4 が必要
  HPDF.Compression := cmFlateDecode;
  HPDF.BeginDoc;
  ImIdx := HPDF.AddImageWithSMask(W, H, RGB, Alpha);
  HPDF.CurrentPage.ShowImage(ImIdx, 80, 80, 256, 256, 0);
  HPDF.EndDoc;
end;

 

関連項目

AddImage, THPDFPage.ShowImage, Version, PDF フィルターサポート