Autor Beitrag
fuulf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 13.05.10 15:09 
Hallo,

ich habe eine 100x100 Pixel Bitmap, welche außen weiß ist. Ich würde für diese Bitmap gerne weiß als transparente Farbe definieren und dann die Bitmap über eine andere (Hintergrund-) 100x100 Pixel Bitmap legen. Um das so enstehende Bild auf dem Formular zu visualisieren dachte ich an ein Image. Ich habe mir dazu folgenden Code überlegt:

ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Image: TImage;
  Bmp1, Bmp2: TBitmap;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Bmp1 := TBitmap.Create;
  Bmp1.Height := 100;
  Bmp1.Width  := 100;
  Bmp1.LoadFromFile('Bmp1.bmp');


  Bmp2 := TBitmap.Create;
  Bmp2.Height := 100;
  Bmp2.Width  := 100;
  Bmp2.TransparentMode := tmFixed;
  Bmp2.TransparentColor := clWhite;
  Bmp2.Transparent := true;


  Image := TImage.Create(Form1);
  Image.Height := 100;
  Image.Width  := 100;

  Image.Picture.Bitmap := Bmp1;
  Image.Picture.Bitmap := Bmp2;
  Image.Parent := Form1;
end;

end.


Doch das unerwartete Endergebnis: Man sieht am Ende nur die zweite Bitmap. Es scheint so, dass bei Image.Picture.Bitmap := Bmp2; der vorherige Bitmap-Inhalt einfach überschrieben wird.

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 13.05.10 15:13 
So ist es auch. Das ist das gleiche als würdest du folgendes schreiben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  aInteger := 5;
  anotherInteger := 10;

  targetInteger := aInteger;
  targetInteger := anotherInteger;


du könntest vielleicht mittels bmp1.Canvas.Draw oder ähnlichem das 2. Bitmap transparent aufs erste zeichnen und dann das erste einfach anzeigen lassen.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
fuulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 13.05.10 15:29 
Hey,
der folgende Quellcode funktioniert immer noch nicht. Jetzt wird gar nichts mehr auf dem Formular angezeigt:

ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Image: TImage;
  Bmp1, Bmp2: TBitmap;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Bmp1 := TBitmap.Create;
  Bmp1.Height := 100;
  Bmp1.Width  := 100;
  Bmp1.LoadFromFile('Bmp1.bmp');


  Bmp2 := TBitmap.Create;
  Bmp2.Height := 100;
  Bmp2.Width  := 100;
  Bmp2.TransparentMode := tmFixed;
  Bmp2.TransparentColor := clWhite;
  Bmp2.Transparent := true;
  Bmp2.LoadFromFile('Bmp2.bmp');

  Bmp1.Canvas.Draw(0, 0, Bmp2);

  Image := TImage.Create(Form1);
  Image.Height := 100;
  Image.Width  := 100;

  Image.Picture.Bitmap := Bmp1;
end;

end.



Muss man vielleicht noch CopyMode auf einen anderen Wert setzen?

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 13.05.10 15:32 
Könnte sein. Das mit dem Canvas.Draw war mehr eine Anregung als eine Komplettlösung. Es wäre auch möglich das du eine komplett andere Methode von Canvas nehmen musst, aber auf jeden Fall müsstest du das eine Bitmap aufs andere Zeichnen.

ein kleines einführungstutorial zu Bitmaps gibt es hier.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
fuulf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 13.05.10 15:33 
Sorry, ich hab das Image.Parent := Form1; vergessen!

Jetzt funktioniert alles, vielen Dank :-]