[TImage] Drawing an image lazarus / 31-LCL ---------------------------------------------------------------------- Neuromancer · 2014-03-15 18:19 Hello, I am trying to display a game map using a TImage. I want a black background, and then I would display the tiles. Code: [Select]procedure DrawMap; var     i, j : Integer; begin     frmMain.imgMap.Canvas.Brush.Color := clBlack;     frmMain.imgMap.Canvas.Rectangle(0, 0, frmMain.imgMap.Width, frmMain.imgMap.Height);     for i := ShiftX to ShiftX+10 do     begin         for j := ShiftY to shiftY+10 do             DrawTile(i, j);     end; end; procedure DrawTile(AX : Integer; AY : Integer); var     LPosition : TPoint; begin     if gGame.FMap.IsVisible(AX, AY) then     begin         LPosition := MapToScreen(AX, AY);         gLogger.Log('(%d, %d)', [LPosition.X, LPosition.Y]);         case gGame.FMap.GetTileAt(AX, AY) of         OCEAN : frmMain.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('ocean'));         GRASSLAND : frmMain.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('grassland'));         end;         frmMain.imgMap.Canvas.TextOut(LPosition.X+30, LPosition.Y+30, Format('%d, %d', [ax, ay]));     end; end; But it does not work well : only the black background is displayed. ---------------------------------------------------------------------- zeljko · 2014-03-15 20:55 Where it does not work ok ? Linux, Windows, Mac ? Widgetset ? If you're on mac or qt widgetset then definitelly it cannot work since you're painting outside of paint event. ---------------------------------------------------------------------- Neuromancer · 2014-03-15 21:34 Of course it won't work : I wrote : Code: [Select]OCEAN : frmMain.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('ocean')); GRASSLAND : frmMain.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('grassland')); But I should write : OCEAN : frmMain.imgMap.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('ocean')); GRASSLAND : frmMain.imgMap.Canvas.Draw(LPosition.X, LPosition.Y, GetImage('grassland')); ---------------------------------------------------------------------- User137 · 2014-03-16 09:41 You should also be drawing on frmMain.imgMap.Bitmap.Canvas. That way your drawings will not disappear even if you minimize the window. Or even better, draw on custom TBitmap and then draw it in 1 go to the image.bitmap.canvas. It is a form of doublebuffering which eliminates flickering. Edit: could be image.picture.bitmap.canvas... It's time since i used it.