THotPDF.AddImageWithSMask Method

 

THotPDF.AddImageWithSMask

THotPDF

 

Viršus  Ankstesnis  Kitas

Prideda spalvinį image XObject kartu su PDF 1.4 soft-mask image XObject (ISO 32000-1 8.9.5.4), kad gautas paveikslas turėtų pilną skaidrumą kiekvienam pikseliui, o ne dvejetainį įjungta / išjungta apribojimą, būdingą senajam /ImageMask keliui

 

Delphi syntax:

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

function AddImageWithSMask32(Bitmap32: TBitmap): Integer;

 

C++ syntax:

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

__property int AddImageWithSMask32(TBitmap* Bitmap32);

 

Aprašas

SMask vaizdai turi nepriklausomą 8 bitų DeviceGray kanalą, kurio šviesumas piešimo metu valdo spalvoto vaizdo alfa (0 = visiškai skaidrus, 255 = visiškai nepermatomas). HotPDF abu sluoksnius išveda kaip Flate-suspaustus Image XObjects, prijungia spalvoto vaizdo žodyną /SMask prie švelnaus kaukės XObject ir grąžina XImages indeksą, kurį THPDFPage.ShowImage priima tiesiogiai, todėl visas tolesnis talpinimo kodas lieka be pakeitimų

 

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)

Patogus apkrovimas įprastam „Turiu PNG su alfa“ scenarijui. TBitmap turi būti su PixelFormat = pf32bit; HotPDF tiesiogiai nuskaito BGRA ScanLine eilutes, perskirsto jas į R G B spalvų plokštumą ir nukopijuoja A baitą į alfa plokštumą, prieš perduodant į pirminį AddImageWithSMask pateikimą

 

Grąžinama: XImages indeksas, toks pat kaip grąžina AddImage; jį perduokite THPDFPage.ShowImage, kad puslapyje pateiktumėte paveikslėlį. Grąžinama -1, kai StrictVersionLock įjungtas ir aktyvi Versija yra žemesnė nei PDF 1.4 (priešingu atveju versija automatiškai padidinama iki 1.4)

 

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