THotPDF.AddImageWithSMask 메서드

 

THotPDF.AddImageWithSMask

THotPDF

 

맨 위  이전  다음

Color image XObject와 PDF 1.4 soft-mask image XObject(ISO 32000-1 8.9.5.4)를 함께 추가하여 결과 picture가 legacy /ImageMask path의 binary on/off 제한 대신 full per-pixel transparency를 갖도록 합니다

 

Delphi 구문:

function AddImageWithSMask(Width, Height: Integer; const RGB: TBytes; const Alpha: TBytes): Integer;

function AddImageWithSMask32(Bitmap32: TBitmap): Integer;

 

C++ 구문:

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

__property int AddImageWithSMask32(TBitmap* Bitmap32);

 

설명

SMask image는 paint time에 color image의 alpha를 구동하는 독립 8-bit DeviceGray channel을 가집니다(0 = fully transparent, 255 = fully opaque). HotPDF는 두 plane을 모두 Flate-compressed image XObject로 emit하고, color image dictionary의 /SMask entry를 soft-mask XObject에 연결하며, THPDFPage.ShowImage가 직접 받는 XImages index를 반환합니다. Downstream placement code는 모두 변경 없이 동작합니다

 

AddImageWithSMask(Width, Height, RGB, Alpha)

- Width / Height: pixel dimensions, identical for both planes.

- RGB: Width * Height * 3 bytes, row-major top-down, R G B interleaved per pixel (no row padding).

- Alpha: Width * Height bytes, row-major top-down, 8-bit luminosity per pixel.

 

AddImageWithSMask32(Bitmap32)

일반적인 "alpha가 있는 PNG가 있음" workflow를 위한 convenience overload입니다. TBitmapPixelFormat = pf32bit여야 합니다. HotPDF는 BGRA ScanLine row를 직접 읽고 color plane을 위해 R G B로 재배열한 뒤 A byte를 alpha plane에 복사하고 raw AddImageWithSMask entry point로 위임합니다

 

반환 값: AddImage가 반환하는 것과 동일한 XImages index입니다. Page에 picture를 배치하려면 THPDFPage.ShowImage에 전달하십시오. StrictVersionLock이 켜져 있고 active Version이 PDF 1.4보다 낮으면 -1을 반환합니다. 그렇지 않으면 version이 1.4로 auto-bump됩니다

 

Code Example

// Raw-bytes path: build a 64x64 magenta-on-white plane + horizontal
// alpha gradient and place the result on the page
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 requires 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;

 

See Also

AddImage, THPDFPage.ShowImage, Version, PDF Filter Support