Autor Beitrag
Hagbard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 14:59 
Hallo zusammen,

Da Ich in meinem Programm jede Menge Transparente Formen brauche, habe Ich mich mal dieser Funktion aus dem Forum bedient:

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:
procedure TTiCidItem.Blending( bmpBottom, bmpTop : tbitmap; opacity : integer; var bmpResult:tbitmap);
 // bmpBottom: Background Picurte
 // bmpTop   : Foreground Picture
 // opacity  : 1..100 (Shining Intensity of Background)

var x,y:integer;
    p1,p2 : pbytearray;
    temp  : tbitmap;
    hilf, hilf1 : real;
  begin
   temp:=tbitmap.create;
   try
    temp.assign(bmpBottom);
    temp.pixelformat:=pf32bit;

    hilf:=opacity/100;
    hilf1:=abs(1-hilf);

    for y:=0 to temp.Height-1 do begin
     p1:=bmpTop.scanline[y];
     p2:=temp.scanline[y];

     for x:=0 to temp.Width-1 do begin
      p2[x*4]:=trunc(p1[x*4]*hilf+p2[x*4]*hilf1);
      p2[x*4+1]:=trunc(p1[x*4+1]*hilf+p2[x*4+1]*hilf1);
      p2[x*4+2]:=trunc(p1[x*4+2]*hilf+p2[x*4+2]*hilf1);
     end;

    end;
    bmpResult.Assign(temp);
   finally
    temp.free;
   end;
  end;



Die Funktion ist nur leider nicht ganz so schnell wie Ich mir das Vorgestellt habe. Kann man hieran vieleicht noch etwas optimieren?? Hat da jemand eine Idee??

Wäre nett, wenn Sich das mal jemand von Euch anschauen könnte, denn ich steige nicht ganz
dahinter....

Viele Grüße,
Christian

Moderiert von user profile iconPeter Lustig (17:55, 21.05.2004): Code- durch Delphi-Tags ersetzt
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 21.05.04 16:04 
Also ich weiß nicht ob man bei dem Beispiel viel optimieren kann. Also wenn schon, dann ganz anders machen. Aber ich bin kein Experte in diesem Bereich.

Was aber interresant wäre, wie groß sich deine Bilder?

_________________
Gruß
Martin
Hagbard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 16:12 
Hi,
das ist ziemlich unterschiedlich: es kann ein bild von 20*100 sein oder auch ein 1280*1024.
Kommt auf die User an, die das Tool nachher benutzen, aber in der Regel sollten es relativ kleine Bilder sein...


Gruß,
Christian
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 21.05.04 16:22 
Hab gerade was bemerkt: was man auf jeden Fall machen könnte ist Real auszutauschen, z.B. gegen Double. Real ist etwas veraltet und etwas langsam.

Allerdings solltest du beachten, das alles seine Zeit kostet. Und wenn du bei großen Bildern eine Art Blendingfilm machen willst, dann könnte das Rechenleistung benötigen.

_________________
Gruß
Martin
Hagbard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 16:28 
Hi, hab das Real mal gegen einen Double ausgetauscht.
Brachte zwar keine Merkbare Beschleunigung aber trotzdem Danke :-)

Bin mir gerade am überlegen, ob Ich die Blending Funktionen nicht in
eigene Threads auslagere, um damit ein bisserl mehr Performance zu bekommen..

Viele Grüße,
Christian
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Fr 21.05.04 16:44 
Hallo

ich würd anders gestalten. Warum erzeugst du die temp-bitmap? allein das erstellen kostet sehr viel Zeit.
erstell die Zielbitmap einmal außerhalb der Procedure und setze dort größe, und pixelformat und übergib die erstellte Zielbitmap deiner Funktion.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Hagbard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 16:52 
Gute Idee, das werde Ich direkt mal probieren... :-)

Danke

Gruss,
Christian
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 21.05.04 16:54 
Teste das mal. Hab die andere Prozedur umgeschrieben, da ich schon alleine durch die Auswahl an Bitmaps Fehlermeldungen erhalten habe. Das sollte schon mal garnicht passieren.

Was auf jeden Fall sein sollte ist, daß alle Bitmaps 24Bit Farbtiefe haben sollten. Ohne funktioniert das auch nicht, bzw. gibt es eine Fehlermeldung.

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:
procedure Blending2(bmpBottom, bmpTop: TBitmap; Opacity: Byte; bmpResult: TBitmap);
// bmpBottom: Background Picurte
// bmpTop   : Foreground Picture
// opacity  : 1..100 (Shining Intensity of Background)

type
  PixArray = Array [1..3] of Byte;
var
  Temp: TBitmap;
  p1, p2: ^PixArray;
  x, y: Integer;
  f1, f2 : Double;
begin
  //bmpBottom.PixelFormat := pf24bit;
  //bmpTop.PixelFormat := pf24bit;
  //bmpResult.PixelFormat := pf24bit;

  Temp := TBitmap.Create;
  try
    Temp.Assign(bmpBottom);
    Temp.PixelFormat := pf24bit;

    if Opacity > 100 then Opacity := 100;

    f1 := Opacity / 100;
    f2 := Abs(1 - f1);

    for y := 0 to temp.Height - 1 do
    begin
      p1 := bmpTop.ScanLine[y];
      p2 := bmpBottom.ScanLine[y];

      for x:=0 to temp.Width - 1 do
      begin
        p2^[1] := Trunc((p1^[1] * f1) + (p2^[1] * f2));
        p2^[2] := Trunc((p1^[2] * f1) + (p2^[2] * f2));
        p2^[3] := Trunc((p1^[3] * f1) + (p2^[3] * f2));

        Inc(p1);
        Inc(p2);
      end;
    end;

    bmpResult.Assign(Temp);
    bmpResult.Modified := True;
  finally
    Temp.Free;
  end;
end;


Sag mir Bescheid ob der schneller ist.

_________________
Gruß
Martin
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 21.05.04 16:58 
Keldorn hat folgendes geschrieben:
Hallo

ich würd anders gestalten. Warum erzeugst du die temp-bitmap? allein das erstellen kostet sehr viel Zeit.
erstell die Zielbitmap einmal außerhalb der Procedure und setze dort größe, und pixelformat und übergib die erstellte Zielbitmap deiner Funktion.

Mfg Frank


Wie wirkt es sich aus, wenn direkt in einer Bitmap gezeichnet wird? Je nachdem wie langsam gezeichnet wird, kann man das am Bildschirm beobachten. Deshalb ist es gelegentlich zu empfehlen eine Zeichnung in einem Puffer zuerst fertig zu bearbeiten und dann das ganze Ergebnis übergeben.

_________________
Gruß
Martin
Hagbard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 17:09 
temp Bitmap entfernt:

Also, gemerkt habe Ich da nichts von mehr Geschwindigkeit, aber es wirkt sich auch nicht negativ aus. Allerdings ist mein Objekt auf dem Gezeichnit wird auch Invisible und wird erst wenn alles fertig ist Sichtbar.


Deine Funktion werde Ich jetzt mal testen....

Danke schonmal :-)
Hagbard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Fr 21.05.04 17:14 
Deine Funktion macht zwar mein Bild Transparent, allerdings sind jetzt alle Bilder zu 100% Transparent. Geschwindigkeit ist gleich geblieben...

Ich muß mir das nochmal genau anschauen, warum er das macht.... Nur leider nicht mehr heute, da mein Fahrgemeinschaftspartner heim will :-(

Viele Grüße und Vielen Dank,
Christian