THotPDF.AddImageWithSMask Method

 

THotPDF.AddImageWithSMask

THotPDF

 

Topo  Anterior  Próxima

Adiciona um Image XObject colorido junto com um Image XObject de soft mask PDF 1.4 (ISO 32000-1 8.9.5.4) de modo que a imagem resultante carregue transparência completa por pixel em vez do limite binário on/off do caminho legado de /ImageMask.

 

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

 

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

 

Descrição

Imagens SMask carregam um canal independente DeviceGray de 8 bits cuja luminosidade dirige o alfa da imagem colorida no momento da pintura (0 = totalmente transparente, 255 = totalmente opaco). O HotPDF emite ambos os planos como Image XObjects comprimidos com Flate, liga a entrada /SMask do dicionário da imagem colorida ao XObject de soft mask e retorna um índice XImages que THPDFPage.ShowImage aceita diretamente — todo o código de posicionamento a jusante funciona inalterado.

AddImageWithTransparency e AddImageWithTransparency32 são apelidos de nomenclatura para o mesmo fluxo de soft mask do PDF 1.4. Eles existem para pontos de chamada que pensam em termos de imagens transparentes em vez da terminologia de dicionários do PDF

 

AddImageWithSMask(Width, Height, RGB, Alpha)

- Width / Height: dimensões em pixels, idênticas para ambos os planos.

- RGB: Width * Height * 3 bytes, linha a linha de cima para baixo, R G B intercalados por pixel (sem padding de linha).

- Alpha: Width * Height bytes, linha a linha de cima para baixo, luminosidade de 8 bits por pixel.

 

AddImageWithSMask32(Width, Height, Pixels)

Sobrecarga de conveniência para entrada RGBA empacotada de 32 bits. Pixels deve conter Width * Height * 4 bytes na ordem R, G, B, A. O HotPDF divide o buffer no plano de cor RGB e no plano de alfa de 8 bits antes de delegar a AddImageWithSMask

 

Return value: um índice em XImages idêntico ao que AddImage retorna; passe-o a THPDFPage.ShowImage para colocar a figura em uma página. Retorna -1 quando StrictVersionLock está ligado e o Version ativo está abaixo do PDF 1.4 (caso contrário a versão é promovida automaticamente para 1.4).

 

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

 

See Also

AddImage, THPDFPage.ShowImage, Version, PDF Filter Support