Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created February 26, 2017 17:29
Show Gist options
  • Save JordiCorbilla/b4eb68aa9cbb1b30a6f1fff457ef628e to your computer and use it in GitHub Desktop.
Save JordiCorbilla/b4eb68aa9cbb1b30a6f1fff457ef628e 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;
begin
image := GetImage(index);
//start painting
image.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
image.Canvas.Fill.Color := TAlphaColors.Lime
else
image.Canvas.Fill.Color := TAlphaColors.Black;
inc(k);
image.Canvas.Stroke.Color := TAlphaColors.Green;
image.Canvas.Stroke.Thickness := 0;
//Use LocalToAbsolute to paint within the boundaries of TImage and not the form canvas!
MyRect := TRectF.Create(image.LocalToAbsolute(TPointF.Create(round(((i)*image.Width)/rows), round(((j)*image.Height)/rows))), round((image.Width)/rows), round((image.Height)/rows));
image.Canvas.FillRect(MyRect, 0, 0, AllCorners, 1);
end;
end;
image.Canvas.EndScene;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment