Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created February 26, 2017 17:54
Show Gist options
  • Save JordiCorbilla/2856e00382f3801de1404a0158a0e6fa to your computer and use it in GitHub Desktop.
Save JordiCorbilla/2856e00382f3801de1404a0158a0e6fa to your computer and use it in GitHub Desktop.
procedure TForm1.PaintImage(index: integer; value : string; rows, columns : integer);
var
image : Timage;
i, j, k : integer;
MyRect: TRectF;
bitmap : TBitmap;
begin
//Retrieve the image we want to paint to
image := GetImage(index);
//Create custom bitmap to paint to
bitmap:=TBitmap.Create(Round(image.Width), Round(image.Height));
bitmap.Canvas.BeginScene;
k := 1;
for i := 0 to rows-1 do
begin
for j := 0 to columns-1 do
begin
if value[k] = '1' then
bitmap.Canvas.Fill.Color := TAlphaColors.Lime
else
bitmap.Canvas.Fill.Color := TAlphaColors.Black;
inc(k);
bitmap.Canvas.Stroke.Color := TAlphaColors.Green;
bitmap.Canvas.Stroke.Thickness := 0;
MyRect := TRectF.Create((TPointF.Create(round(((i)*bitmap.Width)/rows), round(((j)*bitmap.Height)/rows))), round((bitmap.Width)/rows), round((bitmap.Height)/rows));
bitmap.Canvas.FillRect(MyRect, 0, 0, AllCorners, 1);
end;
end;
bitmap.Canvas.EndScene;
//Assign the new bitmap to the image component
image.MultiResBitmap.Bitmaps[1].Assign(bitmap);
image.Bitmap := image.MultiResBitmap.Bitmaps[1];
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment