![]() |
Dynamische Erstellung von TImage Objekten führt zu Fehler in canvas.inc
Guten Abend Delphi Praxis.
Ich hab mich mal grade an ein Programm gemacht, dass dynamisch TImage Objekte aus Bitmapabschnitten erstellt. Das Programm soll ca. 10000 Bitmaps in eine Array of TImage laden und dann in die Form ausgeben. Allerdings gibt es nach ca. 20sec des Wartens diese Meldung: ![]() Hier der dazu gehörende Code:
Delphi-Quellcode:
Liegt es vielleicht daran, dass ich irgendwann zuviele Objekte erstellt habe?
procedure DrawEntities(E: Array_Array_TPoint; Source_Bitmap: TBitmap);
var i, t: Integer; Destination_Rect, Source_Rect: TRect; begin For i := 0 to Length(Entity_image) - 1 do begin Entity_image[i].Free; end; SetLength(Entity_Image,0); For i := 0 to Length(E) - 1 do begin For t := 0 to Length(E[i]) - 1 do begin Setlength(Entity_image, Length(Entity_image) + 1); Entity_image[High(Entity_image)] := TImage.Create(nil); Entity_image[High(Entity_image)].Parent := MAPTEST_form; Entity_image[High(Entity_image)].Height := 5; Entity_image[High(Entity_image)].Width := 5; Entity_image[High(Entity_image)].Top := E[i,t].y*5; Entity_image[High(Entity_image)].Left:= E[i,t].x*5; // Ab hier wird ein bestimmter Abschnitt einer Bitmap in die Array geladen. Destination_Rect := Rect(0,0,5,5); Source_Rect := Rect(i * 5, 1,i * 5 + 5,6); Entity_image[High(Entity_image)].Canvas.FillRect(Destination_Rect); Entity_image[High(Entity_image)].Picture.Bitmap.Canvas.CopyRect(Destination_Rect,Source_Bitmap.Canvas,Source_Rect); Entity_image[High(Entity_image)].BringtoFront; end; end; end; Es gibt eigentlich nur ca. 10 verschiedene Möglichkeiten an Bitmaps mit welcher ein TImage gefüllt kann. Ich glaube aber, dass hier für jedes TImage ein neues Objekt angelegt wird. Da ich nur begrenzte Delphi-Kenntnisse habe und eigentlich nicht mal weiß was ein Parent und TImage.Create(nil) machen, kann ich den Fehler nicht selbst beheben. EDIT: Vielleicht sollte ich ergänzen, dass das Programm durchaus lauffähig ist und nur sobald ich mehr als ca. 3300 TImages in der Array habe, der Fehler auftritt. |
AW: Dynamische Erstellung von TImage Objekten führt zu Fehler in canvas.inc
Zitat:
|
AW: Dynamische Erstellung von TImage Objekten führt zu Fehler in canvas.inc
Sehr schön. Danke genau das wollte ich hören :-D
Hab den Code mal weniger TImage missbrauchend gemacht.
Delphi-Quellcode:
procedure DrawEntities(E: Array_Array_TPoint; Source_Bitmap: TBitmap);
var i, t: Integer; Destination_Rect, Source_Rect: TRect; begin MAPTEST_form.Image3.Width := 500; MAPTEST_form.Image3.Height := 500; For i := 0 to Length(E) - 1 do begin For t := 0 to Length(E[i]) - 1 do begin Destination_rect := Rect(E[i,t].x*5, E[i,t].y*5, E[i,t].x*5 + 5, E[i,t].y*5 + 5); Source_rect := Rect(i * 5, 1, i * 5 + 5, 6); MAPTEST_form.Image3.Canvas.FillRect(Destination_rect); MAPTEST_form.Image3.Picture.Bitmap.Canvas.CopyRect(Destination_rect,Source_Bitmap.Canvas,Source_rect); end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:39 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz