Autor Beitrag
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Fr 13.04.07 10:24 
okay, folgendes für mich gänzlich unverständliches problem:

ich habe eine combobox in der man die größe eines pinsels auswählen kann:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TMain.cbpinselChange(Sender: TObject);
  begin
    baugroese:=cbpinsel.itemindex+1;
    imbau.Width:=baugroese*50;
    imbau.Height:=baugroese*50;  
    loadbaushape(bautyp);
  end;


hierbei stellt imbau (=timage) den pinsel da.

Die procedure loadbaushape sieht folgendermaßen aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
procedure tmain.loadbaushape(typ:string);
var I,J:integer;
    bit:tbitmap;
begin
bit:=tbitmap.create;
 bit.loadfromfile(path+'pics/terrain/'+bautyp+'.bmp');

 for I:=0 to (imbau.width div 50)-1 do
  for J:=0 to (imbau.height div 50)-1 do
  imbau.canvas.draw(I*50,J*50,bit);

  bit.free;

with imbau.Canvas do
  begin
  pen.Width:=2;
  pen.color:=clred;
  moveto(0,0);
  lineto(imbau.width,0);
  lineto(imbau.width,imbau.width);
  lineto(0,imbau.width);
  lineto(0,0);
  end;

edit1.text:=inttostr(imbau.width);
edit2.text:=inttostr(imbau.height);
end;


es wird also abhängig von der größe des pinsels ein bitmap mehrmals in die canvas gezeichnet und abschließend ein rotes rechteck drumherum.

Mein problem ist jetzt, dass man nur den ursprünglichen teil des images sieht (ein feld von 50x50 größe). ich hab schon alles ausprobiert, showmessages um zu gucken ob er es oft genug reinzeichnet, die letztenn zwei zeilen der loadbaushape prozedur sind zur kontrolle ob das imaghe die richtige größe hat und ja er gibt mir die richtige größe an (50x50,100x100 oder 150x150). ich bin mitlerweile echt am verzweifeln und brauche hilfe.....
Jann1k Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Sa 14.04.07 09:01 
wollt den thread mal hochpushen weil das problem immer noch besteht
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 14.04.07 09:31 
Deine zeichenroutine ist unabhänig von baugroesse.
Es sei den TMain.cbpinselChange hat einen Seiteneffekt der im geposteten Queeltext nich zu erkennen ist.
Jann1k Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Sa 14.04.07 09:56 
unabhängig von cbpinsel.onchange?

guckmal:

onchange:

ausblenden Delphi-Quelltext
1:
2:
imbau.Width:=baugroese*50;  
imbau.Height:=baugroese*50;



zeichenroutine:
ausblenden Delphi-Quelltext
1:
2:
3:
 for I:=0 to (imbau.width div 50)-1 do  
  for J:=0 to (imbau.height div 50)-1 do  
  imbau.canvas.draw(I*50,J*50,bit);




sollte doch funktionieren?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 14.04.07 12:20 
Okay, muss wohl meine Brille aufsetzen.
probier doch mal:

ausblenden Delphi-Quelltext
1:
2:
3:
for I:=0 to baugroesse-1 do
 for J:=0 to baugroesse-1 do
  imbau.canvas.draw(I*50*baugroesse,J*50*baugroesse,bit);


Mal was anderes:
Wird Imbau dynamisch erzeugt? Wenn ja wird das Parent(auf die Form) richtig gesetzt und die Sichtbarkeit auf wahr gesetzt?
Am besten Du zeigt mal die Codestelle wo Imbau erzeugt wird.
Magic J
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

WinXP Prof., Vista
Delphi6, Delphi 2009, Java(Eclipse), C++, Basic
BeitragVerfasst: Sa 14.04.07 16:39 
Hi

Sollte die Variable "typ" im Procedurekopf nicht vllt auch verwendet werden?

so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure tmain.loadbaushape(typ:string);  
var I,J:integer;  
    bit:tbitmap;  
begin  
  bit:=tbitmap.create;  
  bit.loadfromfile(path+'pics/terrain/'+ typ +'.bmp');  
...


Gruß Jonas
Jann1k Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Sa 14.04.07 23:06 
user defined image


so mal ein pic damit mans sieht, also bautyp ist eine globale variable und das laden des bildes klappt auch, schliesslich wird es ja einmal korrekt auf die canvas gezeichnet.

der vorschlag von tilo klappt auch nicht, ich hab den verdacht, dass irgendwas mit baugroese nicht stimmt, wennich im formmousemove imbau.width:=150 setze klappt es bei imbau.width:=baugroesse*50; nicht Oo

imbau ist übrigens ein auf die form gezogenen image, wird also nicht zur laufzeit erzeugt
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 15.04.07 00:28 
Du wirst es nicht glauben: das Problem hab ich auch grade.

Angenommen ich habe Image.Canvas.Fillrect(0,0,image.width, image.height) in einer Prozedur. Wenn sich die Größe des Images ändert und ich neu zeichne (also die Proc aufrufe) bleibt das gezeichnete Feld gleich groß wie es am Anfang war.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: So 15.04.07 07:20 
user profile iconMartok hat folgendes geschrieben:
Du wirst es nicht glauben: das Problem hab ich auch grade.

Angenommen ich habe Image.Canvas.Fillrect(0,0,image.width, image.height) in einer Prozedur. Wenn sich die Größe des Images ändert und ich neu zeichne (also die Proc aufrufe) bleibt das gezeichnete Feld gleich groß wie es am Anfang war.


Erzeuge imbau mal Dynamisch.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 15.04.07 07:41 
Logisch. Ihr ändert ja auch nicht die Bildgröße, sondern die Größe des Images. Ändert zuätzlich noch Image1.Picture.Bitmap.Width / .Height.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Jann1k Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: So 15.04.07 07:55 
:flehan:

großer Meister GTA-Place, danke, danke, danke das funktioniert. Nur wieso klappt das denn wenn ich schreib imbau.width:=150?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 15.04.07 08:01 
Kann ich nicht genau sagen, bei mir funktioniert es nur, wenn ich die Bitmapgröße zusätzlich ändere.

Hier nochmal die funktionierende Lösung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var
  I, J: Integer;
begin
  for I := 0 to (Image1.Width div 50) - 1 do
    for J := 0 to (Image1.Height div 50) - 1 do
      Image1.Canvas.Draw(I * 50, J * 50, Image2.Picture.Bitmap);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Image1.Width  := 500;
  Image1.Height := 500;
  Image1.Picture.Bitmap.Width  := 500;
  Image1.Picture.Bitmap.Height := 500;
end;

Image1 hat am Anfang die Größe 250x250. Bei Klick auf Button1 wird das Bild von Image2 mehrmals auf Image1 draufgemalt. Klickt man dann auf Button2 und erneut auf Button1, wird so wie gewünscht, das komplette Feld (500x500) bemalt.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)