Autor Beitrag
stratege15
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 13.08.03 10:37 
Hallo,
kann mir plzz irgendjemand ein Beispiel zu Alphablending geben?
Folgendes Problem:
Wie kann ich einen bestimmten Bereich einer BMP ausschneiden, in diesen Bereich eine andere BMP transparent kopieren und das fertige Bild dann auf dem Bildschirm anzeigen lassen?
Eggi
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 33

Win 2000, Win XP
D7 Prof
BeitragVerfasst: Mi 13.08.03 11:20 
Hallo,

ich nutze dazu folgende Funktion. T1 und T2 sind die beiden Ausgangsbilder. Das Ergebnisbild wird in T abgelegt. Mit Deckkraft ist gegeben wie stark das erste Bild zu sehen sein soll. Deckkraft sollte zwischen 0 und 100 liegen.

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:
function BlendImgs(t1,t2:tbitmap; deckkraft:integer; var t:tbitmap):integer;
var x,y:integer;
    p1,p2:pbytearray;
    temp:tbitmap;
    hilf, hilf1:real;
begin
 temp:=tbitmap.create;
 try
  temp.pixelformat:=pf24bit;

  temp.assign(t2);

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

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

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

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


Eggi
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 13.08.03 11:25 
Eggi hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
...
  temp.pixelformat:=pf24bit;

  temp.assign(t2);
...



es muss heißen

ausblenden Delphi-Quelltext
1:
2:
  temp.assign(t2);
  temp.pixelformat:=pf24bit;


weil sonst erst das pixelformat geändert wird und dann das von der andreen Bitmap übernommen wird, wodurch ggf kein Scanline funzt.
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 13.08.03 11:31 
Titel: danke
super! viielen vieelen dank! kann ich gut gebrauchen!

es gibt wohl doch noch hilfsbereite menschen auf dieser welt :D
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 13.08.03 11:46 
Titel: noch was
nur eine frage noch: wie könnte ich jetzt aus bitmap1 einen bestimmten bereich rausschneiden, eine kleinere bitmap (deren schwarzer hintergrund durchsichtig angezeigt wird) auf diese fügen und das dann gemeinsam anzeigen lassen (die finale bitmap hat dann die größe der größeren 1. bitmap) ?`

(ich glaub das nennt man nicht alpha-blendig oder :roll: )
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Mi 13.08.03 16:19 
Titel: ok
ok .. das hab ich soweit .. nur hab ich folgendes problem:
wenn ich ein sprite auf den background kopier, wird es ganz normal kopiert.. ich hätte es aber gerne "transparent" kopiert, d.h. der hintergrund wird durchsichtig (z.b. die farbe schwarz).
ausblenden Quelltext
1:
2:
3:
  quelle:=rect(0,0,sprite.width,sprite.height);
  ziel:=rect(x,y,x+sprite.width,y+sprite.height);     
  feld.canvas.copyrect(ziel,sprite.canvas,quelle);
stratege15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Do 14.08.03 11:23 
kann mir da jemand helfen?
Hagbard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Di 04.05.04 09:10 
für alle die es interessiert:
Mit der CLX werden keine 24Bit Bitmaps unterstützt. (32Bit ist aber kein Problem)
Ich habe die Funktion mal umgeschrieben, damit Sie auch mit der CLX läuft:


ausblenden 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:
procedure TTiCidItem.Blending( bmpBottom, bmpTop:tbitmap; opacity:integer; var bmpResult:tbitmap);
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;