THotPDF.AddImageWithSMask Method

 

THotPDF.AddImageWithSMask

THotPDF

 

למעלה  הקודם  הבא

מוסיף image XObject צבעוני יחד עם image XObject של soft-mask עבור PDF 1.4 ‏(ISO 32000-1 8.9.5.4), כך שהתמונה המתקבלת נושאת שקיפות מלאה לכל pixel במקום מגבלת on/off בינארית של מסלול /ImageMask הישן

 

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

 

תיאור

תמונות SMask נושאות ערוץ DeviceGray עצמאי של 8-bit שה-luminosity שלו מניע את alpha של התמונה הצבעונית בזמן הצביעה (0 = שקוף לגמרי, 255 = אטום לגמרי). HotPDF פולטת את שני המישורים כ-image XObjects דחוסי Flate, מחברת את ערך /SMask במילון התמונה הצבעונית אל soft-mask XObject, ומחזירה index של XImages ש-THPDFPage.ShowImage מקבל ישירות; כל קוד המיקום downstream עובד ללא שינוי

 

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)

overload convenience לתהליך הנפוץ “יש לי PNG עם alpha”. ‏TBitmap חייב להיות עם PixelFormat = pf32bit; HotPDF קוראת את שורות BGRA ScanLine ישירות, מסדרת מחדש ל-R G B עבור מישור הצבע, ומעתיקה את byte ‏A למישור alpha לפני העברה לנקודת הכניסה הגולמית AddImageWithSMask

 

הערך המוחזר: index לתוך XImages זהה לזה שמחזיר AddImage; העבר אותו ל-THPDFPage.ShowImage כדי למקם את התמונה בעמוד. מוחזר -1 כאשר StrictVersionLock מופעל וה-Version הפעילה נמוכה מ-PDF 1.4; אחרת הגרסה עולה אוטומטית ל-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