Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 18.06.08 17:59 
Hallo,

ich suche jetzt schon seit ner halben Stunde einen Befehl, mit dem ich ganz einfach bei Koordinaten in einem TImage ein anderes einfügen kann. Mit CopyRect geht es nicht und wenn ich es direkt mache geht es auch nicht. :evil:

Hier mein Ansatz:

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 TForm1.Button1Click(Sender: TObject);
var
  image: TImage;
begin
  image := TImage.Create(nil);
  image.Picture := TPicture.Create;
  image.Picture.Bitmap := TBitmap.Create;
  image.Picture.Bitmap.Width := 15;
  image.Picture.Bitmap.Height := 15;
  image.Picture.Bitmap.PixelFormat := pf8bit;
  image.Picture.Bitmap.Canvas.Pixels[5, 5] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 6] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 7] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 8] := clBlack;
  InsertInImage(4, 4, image, Image1);
end;

procedure TForm1.InsertInImage(x: Integer; y: Integer; img, dest: TImage);
var
  i, j: Integer;
begin
  for i := x to img.Width - 1 do
    for j := y to img.Height - 1 do
    begin
      dest.Picture.Bitmap.Canvas.Pixels[i, j] := img.Picture.Bitmap.Canvas.Pixels[i - x, j - y];
    end;
end;

Image1 ist ein TImage auf der Form, welches groß genug ist (296 | 80). Was mache ich falsch? :(

Gruß,
Hendi
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 18.06.08 18:33 
user profile iconHendi48 hat folgendes geschrieben:
Hallo,

ich suche jetzt schon seit ner halben Stunde einen Befehl, mit dem ich ganz einfach bei Koordinaten in einem TImage ein anderes einfügen kann. Mit CopyRect geht es nicht und wenn ich es direkt mache geht es auch nicht


1.: Wo gibst du image wieder frei (woanders als in Button1click ist es ja nicht möglich, da es eine lokale Variable ist.
2.:
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 TForm1.Button1Click(Sender: TObject);
var
  image: TImage;
var x, y: integer;
begin
  try
  image := TImage.Create(image1);
  image.Picture := TPicture.Create;
  image.Picture.Bitmap := TBitmap.Create;
  image.Picture.Bitmap.Width := 15;
  image.Picture.Bitmap.Height := 15;
///////////////////////////////////////////////////////////////
  image.Picture.Bitmap.Canvas.Pixels[5, 5] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 6] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 7] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 8] := clBlack;
  image.left:= image1.left+ x;
  image.top := image1.top + y;
  image1.bringtofront;
//////////////////////////////////////
//andere Anweisungen
  finally
  image.picture.bitmap.destroy;
  image.picture.destroy;
  image.destroy
  end;
end;
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 18.06.08 18:43 
Hallo,
dannke für die Antwort, aber wären dann die Pixel in Image1 drin oder "liegt" image nur sozusagen auf Image1 drauf, sodass ich das wieder ansprechen muss wenn ich was ändern möchte?

Gruß,
Hendi
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 18.06.08 19:19 
Hallo,

vielleicht hilft dir die Prozedur

ausblenden Delphi-Quelltext
1:
Image.Picture.Bitmap.Canvas.Draw(X, Y, Graphic);					

weiter. Das ist dann auch im einiges schneller als Canvas.Pixels ;)

Grüße,
Yogu
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 18.06.08 19:28 
So,
mein Code sieht jetzt wie folgt aus, aber immer noch dasselbe Problem: Es passiert nichts! :(

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:
procedure TForm1.Button1Click(Sender: TObject);
var
  image: TImage;
begin
  image := TImage.Create(nil);
  image.Picture := TPicture.Create;
  image.Picture.Bitmap := TBitmap.Create;
  image.Picture.Bitmap.Width := 15;
  image.Picture.Bitmap.Height := 15;
  image.Picture.Bitmap.PixelFormat := pf8bit;
  image.Picture.Bitmap.Canvas.Pixels[5, 5] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 6] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 7] := clBlack;
  image.Picture.Bitmap.Canvas.Pixels[5, 8] := clBlack;
  InsertInImage(10, 10, image, Image1);
end;

procedure TForm1.InsertInImage(x: Integer; y: Integer; img, dest: TImage);
begin
  dest.Picture.Bitmap.Canvas.Draw(x, y, img.Picture.Graphic);
  dest.BringToFront;
end;
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 18.06.08 20:47 
1: image wieder freigeben
2: image :=timage.create (self)!!!
3: parent zuweisen und visible auf true setzen!!
4: Wieso zeichnest du eigentlich nicht auf dem Canvas des images anstatt auf dem Canvas des Bitmaps??
5: Wieso zeichnest du die Punkte nicht gleich in das richtige Image??
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mi 18.06.08 21:35 
Hi,

TImage kapselt eine Grafik, in deinem Beispiel wird es stets eine Bitmap sein. Es wäre also etwas "direkter", eine Bitmap zu verwenden, statt eine visuelle Kompnente zu vergewaltigen :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.Button1Click(Sender: TObject);
var
  tmpBmp: TBitmap;
  i: Integer;
begin
  tmpBmp := TBitmap.Create;
  tmpBmp.SetSize(15, 15);
  tmpBmp.PixelFormat := pf8bit;
  tmpBmp.Canvas.Pixels[5, 5] := clBlack;
  tmpBmp.Canvas.Pixels[5, 6] := clBlack;
  tmpBmp.Canvas.Pixels[5, 7] := clBlack;
  tmpBmp.Canvas.Pixels[5, 8] := clBlack;
//oder kürzer:
  for i := 5 to 8 do
    tmpBmp.Canvas.Pixels[5, i] := clBlack;
// /oder kürzer
  Image1.Canvas.Draw(10, 10, tmpBmp);
end;

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 19.06.08 16:15 
Danke, so geht es :D

Gruß,
Hendi
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 19.06.08 16:54 
user profile iconBoldar hat folgendes geschrieben:
Wieso zeichnest du die Punkte nicht gleich in das richtige Image??

Das wäre sicher der bessere Weg. So wie das aussieht, zeichnest du an Position (10|10) ein 15x15 großes, weißes Quadrat, und eine schwarze Linie von (15|15) nach (15|18). Du musst nur die Funkionen Canvas.FillRect und Canvas.MoveTo bzw. Canvas.LineTo auf Image1 anwenden.