How can i edit the Image of a sprite directly (like drawing something to it)?

[pascal]
Background.Image:= fMain.Diverse.Items.Find('background');

TempPic:= Background.Image.Picture;
MaxTile:= fMain.Tiles.Items.Count;

TempPic.Free;
TempPic:= TPicture.Create;

TempPic.Bitmap.Canvas.FillRect(Rect(0,0,TempPic.Wi dth,TempPic.Height));

TempPic.Bitmap.SetSize(Room[CurrentRoom].Width*32,Room[CurrentRoom].Height*32);

for z := 0 to High(Room[CurrentRoom].Layer) do
begin
for y := 0 to Room[CurrentRoom].Height -1 do
begin
for x := 0 to Room[CurrentRoom].Width-1 do
begin
if (x >= 0) and (y >= 0) then //check so x or y is not too low
begin
Tile:= Room[CurrentRoom].Layer[z].Tile[x,y]; //Get the tile for the coordinates x,y in layer l
if (Tile <MaxTile>= 0) then //Check so Tile does not contain an illegal value
TempPic.Bitmap.Canvas.Draw((32*x),(32*y),fMain.Til es.Items[Tile].Picture.Graphic); //Draw the tile in place
end;
end;
end;
end;
TempPic.Graphic:= TempPic.Bitmap;

[/pascal]

this does not work properly (it works once, but not twice. dont know why)