THotPDF.AddImageWithSMask-Methode

 

THotPDF.AddImageWithSMask

THotPDF

 

Oben  Zurück  Weiter

Fügt ein farbiges Bild-XObject zusammen mit einem Soft-Mask-Bild-XObject aus PDF 1.4 hinzu (ISO 32000-1 8.9.5.4), sodass das Ergebnis volle Transparenz pro Pixel trägt statt der binären Ein/Aus-Grenze des älteren /ImageMask-Pfads.

 

Delphi syntax:

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++ syntax:

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);

 

Description

SMask-Bilder tragen einen eigenständigen 8-Bit-DeviceGray-Kanal, dessen Luminanz beim Zeichnen den Alphawert des Farbbilds steuert (0 = vollständig transparent, 255 = vollständig deckend). HotPDF schreibt beide Ebenen als Flate-komprimierte Bild-XObjects, verdrahtet den Eintrag /SMask im Dictionary des Farbbilds mit dem Soft-Mask-XObject und gibt einen XImages-Index zurück, den THPDFPage.ShowImage direkt akzeptiert - der gesamte nachgelagerte Platzierungscode funktioniert unverändert.

AddImageWithTransparency und AddImageWithTransparency32 sind Namensaliase für denselben Soft-Mask-Workflow aus PDF 1.4. Sie sind für Aufrufstellen gedacht, die in transparenten Bildern statt in der Terminologie der PDF-Dictionaries denken

 

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(Width, Height, Pixels)

Komfort-Überladung für gepackte 32-Bit-RGBA-Eingaben. Pixels muss Width * Height * 4 Bytes in der Reihenfolge R, G, B, A enthalten. HotPDF teilt den Puffer in die RGB-Farbebene und die 8-Bit-Alphaebene auf, bevor es an AddImageWithSMask delegiert

 

Rückgabewert: ein Index in XImages, identisch mit dem, den AddImage zurückgibt; übergeben Sie ihn an THPDFPage.ShowImage, um das Bild auf einer Seite zu platzieren. Gibt -1 zurück, wenn StrictVersionLock aktiv ist und die aktuelle Version unter PDF 1.4 liegt (andernfalls wird die Version automatisch auf 1.4 angehoben).

 

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