var
Img: TSingleImage;
Src, Bitmap: PByte;
begin
... load or create image ...
// First convert image to 8bpp grayscale
Img.Format := ifGray8;
Src := Img.Bits;
// Create bilevel image using 128 as treshold
for Y := 0 to Img.Height - 1 do
for X := 0 to Img.Width - 1 do
begin
if Src^ > 128 then
Src^ := 255
else
Src^ := 0;
Inc(Src);
end;
// Allocate memory for 1bpp image
WidthBytes := (Img.Width + 7) div 8; // Scanlines size must be byte-aligned
GetMem(Bitmap, WidthBytes * Img.Height);
FillChar(Bitmap^, WidthBytes * Img.Height, 0); // Needed by conversion code
Src := Img.Bits;
// Now copy pixels to Bitmap
for Y := 0 to Img.Height - 1 do
for X := 0 to Img.Width - 1 do
begin
Bitmap[Y * WidthBytes + X div 8] := Bitmap[Y * WidthBytes + X div 8] or // OR current value of byte with following:
(Src^ and 1) // To make 1 from 255, 0 remains 0
shl (7 - (X mod 8)); // Put current bit to proper place in byte
Inc(Src);
end;
QuoteJust have to look at the API.
Page created in 0.036 seconds with 19 queries.