|
Lägger till ett XObject för färgbild tillsammans med ett XObject för PDF 1.4-mjukmaskbild (ISO 32000-1 8.9.5.4), så att den resulterande bilden bär full transparens per pixel i stället för den binära på/av-begränsningen i den äldre /ImageMask-vägen
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);
Beskrivning
SMask-bilder bär en oberoende 8-bitars DeviceGray-kanal vars luminans styr färgbildens alfa vid målning (0 = helt transparent, 255 = helt opak). HotPDF skriver båda planen som Flate-komprimerade bild-XObject, kopplar färgbildordbokens /SMask-post till mjukmaskens XObject och returnerar ett XImages-index som THPDFPage.ShowImage accepterar direkt - all efterföljande placeringskod fungerar oförändrat
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)
Bekväm överlagring för det vanliga arbetsflödet "jag har en PNG med alfa". TBitmap måste ha PixelFormat = pf32bit; HotPDF läser BGRA ScanLine-raderna direkt, ordnar om till R G B för färgplanet och kopierar A-byten till alfaplanet innan anropet skickas vidare till den råa AddImageWithSMask-ingångspunkten
Returvärde: ett index i XImages som är identiskt med det som AddImage returnerar; skicka det till THPDFPage.ShowImage för att placera bilden på en sida. Returnerar -1 när StrictVersionLock är på och den aktiva Version är lägre än PDF 1.4 (annars höjs versionen automatiskt till 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;
Se även
AddImage, THPDFPage.ShowImage, Version, PDF Filter Support
|