// bmp is a TBitmap which contains the grayscale image
// Convert the DDB to a DIB
bmp.HandleType := bmDIB;
// Save the bitmap to the file that is attached to this post
bmp.SaveToFile('c:\temp\test.bmp');
// Create a PDF page
pdfpg := FPdf.NewPage(8.5 * 72, 11 * 72, 0);
// FPDFBitmap_CreateEx(w, h, 1, 0, NULL);
pdfbmp := TPdfBitmap.Create(w, h, bfGrays, nil, 0);
imgobj := pdfpg.NewImageObject;
pdfbfr := PByte(pdfbmp.GetBuffer);
bmpLineLen := BytesPerScanLine(bmp.Width, 8, 32);
pdfLineLen := pdfbmp.BytesPerScanline;
// Copy the DIB to the FPDF_BITMAP
for r := 0 to bmp.Height - 1 do
begin
Move(bmp.ScanLine[r]^, pdfbfr^, Min(bmpLineLen, pdfLineLen));
Inc(pdfbfr, pdfLineLen);
end;
imgobj.SetBitmap(1, pdfbmp);
imgobj.Transform(8.5 * 72, 0, 0, 11 * 72, 0, 0);
pdfpg.InsertObject(imgobj);
pdfpg.ApplyChanges;
// Save the PDF to the file attached to this post
FPdf.SaveToFile('c:\temp\test.pdf');