THotPDF.AddImageWithSMask Método

 

THotPDF.AddImageWithSMask

THotPDF

 

Arriba  Anterior  Siguiente

Agrega un XObject de imagen en color junto con un XObject de imagen de máscara suave PDF 1.4 (ISO 32000-1 8.9.5.4), de modo que la imagen resultante lleve transparencia completa por píxel en lugar del límite binario encendido/apagado de la ruta heredada /ImageMask

 

Sintaxis Delphi:

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

function AddImageWithSMask32(Bitmap32: TBitmap): Integer;

 

Sintaxis C++:

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

__property int AddImageWithSMask32(TBitmap* Bitmap32);

 

Descripción

Las imágenes SMask llevan un canal DeviceGray independiente de 8 bits cuya luminosidad controla el alfa de la imagen en color al pintar (0 = completamente transparente, 255 = completamente opaco). HotPDF emite ambos planos como XObjects de imagen comprimidos con Flate, conecta la entrada /SMask del diccionario de la imagen en color al XObject de máscara suave y devuelve un índice XImages que THPDFPage.ShowImage acepta directamente; todo el código de colocación posterior funciona sin cambios

 

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)

Sobrecarga de conveniencia para el flujo común "tengo un PNG con alfa". El TBitmap debe tener PixelFormat = pf32bit; HotPDF lee directamente las filas BGRA de ScanLine, reorganiza a R G B para el plano de color y copia el byte A al plano alfa antes de delegar en el punto de entrada bruto AddImageWithSMask

 

Valor devuelto: un índice en XImages idéntico al que devuelve AddImage; páselo a THPDFPage.ShowImage para colocar la imagen en una página. Devuelve -1 cuando StrictVersionLock está activado y la Version activa está por debajo de PDF 1.4; de lo contrario, la versión se eleva automáticamente a 1.4

 

Ejemplo de código

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

 

Véase también

AddImage, THPDFPage.ShowImage, Version, Soporte de filtros PDF