I need a fast way to create 24 bits bitmaps (and save to a file) in runtime,specifing the Width , Height and color
something like
procedure CreateBMP(Width,Height:Word;Color:TColor;AFile: string);
and call like this
CreateBMP(100,100,ClRed,'Red.bmp');
you can use the Canvas
property of the TBitmap
, setting the Brush
to the color which you want to use, then call FillRect
function to fill the Bitmap.
try something like this :
procedure CreateBitmapSolidColor(Width,Height:Word;Color:TColor;const FileName : TFileName);
var
bmp : TBitmap;
begin
bmp := TBitmap.Create;
try
bmp.PixelFormat := pf24bit;
bmp.Width := Width;
bmp.Height := Height;
bmp.Canvas.Brush.Color := Color;
bmp.Canvas.FillRect(Rect(0, 0, Width, Height));
bmp.SaveToFile(FileName);
finally
bmp.Free;
end;
end;