function RGBtoFPColor(r,g,b: byte): TFPColor;
begin
Result:= FPColor(r*$101,g*$101,b*$101);
end;
procedure stuffing;
var
img: TFPMemoryImage;
cnv: TFPImageCanvas;
writer: TFPCustomimageWriter;
x,y,c: integer;
begin
try
// create a "custom" writer...
writer := TFPWriterBMP.Create;
// ... in order to be able to set the bitmap depth
TFPWriterBMP(writer).BitsPerPixel:= 8;
// create memory image
img:= TFPMemoryImage.Create(128, 128);
try
img.UsePalette:= true;
// Add image palette colors
// seems like the first palette entry is already set to rgb(0,0,0)
// img.Palette.Add(RGBtoFPColor( 0, 0, 0)); // color00
img.Palette.Add(RGBtoFPColor( 99, 207, 99)); // color01
img.Palette.Add(RGBtoFPColor( 57, 51, 255)); // color02
img.Palette.Add(RGBtoFPColor(220, 255, 255)); // color03
cnv := TFPImageCanvas.Create(img);
cnv.Brush.FPColor := RGBtoFPColor( 99, 207, 99);
cnv.Rectangle(10, 10, 60, 64);
cnv.Brush.FPColor := RGBtoFPColor( 57, 51, 255);
cnv.Rectangle(70, 10, 118, 64);
cnv.Brush.FPColor := RGBtoFPColor(220, 255, 255);
cnv.Rectangle(10, 70, 60, 118);
cnv.Brush.FPColor := RGBtoFPColor(225, 0, 0);
cnv.Rectangle(70, 70, 118, 118);
cnv.Free;
(*
// draw some imagery
for y:= 0 to pred(img.height) do
begin
// color cycle through available palette entries.
c:= y shr 2 mod 4;
// assign color to pixels
for x:= 0 to pred(img.width) do img.Pixels[x,y]:= c;
end;
*)
img.SaveToFile ('filename.bmp', writer);
finally
img.Free;
end;
finally
writer.Free;
end;
end;