Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Überblendung zweier Bitmaps (https://www.delphipraxis.net/29703-ueberblendung-zweier-bitmaps.html)

gmarts 13. Sep 2004 14:49


Überblendung zweier Bitmaps
 
Hallo!

Ich möchte zwei Bitmaps ineinander überblenden.

Momentan realisiere ich das mit zwei Image-Komponenten in zwei unterschiedlichen Forms und ändere einfach den
AlphaBlendValue des obenliegenden Forms.
Das erscheint mir aber nicht unbedingt elegant.

Gibt es eine andere und ebendso schnelle Möglichkeit?

MfG

GM

mcjoin 13. Sep 2004 16:40

Re: Überblendung zweier Bitmaps
 
du kannst die bilder in tbitmap lesen und pixel per pixel die Farbkanäle mischen.
kleines Beispiel:
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
type
  TRGBArray = array[0..32767] of TRGBTriple;
  PRGBArray = ^TRGBArray;
var
  x, y: Integer;
  RowA,RowB: PRGBArray;
  bmp1,bmp2 : tbitmap;
begin
  bmp1 := image2.Picture.Bitmap;
  bmp2 := image3.Picture.Bitmap;

  try
  bmp1.PixelFormat := pf24bit;
  for y := 0 to bmp1.Height -1 do
  begin
    rowA := bmp1.ScanLine[y];
    rowB := bmp2.ScanLine[y];
    for x := 0 to bmp1.Width - 1 do
    begin
      rowA[x].rgbtRed := (rowA[x].rgbtRed + rowB[x].rgbtRed) div 2;
      rowA[x].rgbtGreen := (rowA[x].rgbtGreen + rowB[x].rgbtGreen) div 2;
      rowA[x].rgbtBlue := (rowA[x].rgbtBlue + rowB[x].rgbtBlue) div 2;
    end;
  end;
  finally
   image1.Picture.Bitmap := bmp1;
  end;
P.S. : vergiss nicht dass es bloß ein beispiel ist. Anpassungen und SchnickSchnack wie skalieren und prozentuales Mischen habe ich nicht reingebaut. Das zweite Bild wird jedes mal OnClick um 50 % mit dem ersten gemischt.

SirThornberry 13. Sep 2004 16:50

Re: Überblendung zweier Bitmaps
 
Unter welchem Windows soll das ganze funktionieren? Bei XP geht folgendes (ab 2000 glaub ich)
Delphi-Quellcode:
procedure BlendBitmap(Dest: TBitmap; ABlendColor: TColor; ABlendIntensity: Byte = 127; GammaCorrection: Integer = 0);
var LSource: TBitmap;
    LBlendstruct: TBlendFunction;
begin
  LBlendstruct.BlendOp := AC_SRC_OVER;
  LBlendstruct.BlendFlags := 0;
  LBlendstruct.SourceConstantAlpha := ABlendIntensity;// trunc(APercentBlendColor * 255 / 100);
  LBlendstruct.AlphaFormat := 0; //AC_SRC_ALPHA;
  LSource := TBitmap.Create;
  LSource.Width := 1; LSource.Height := 1;
  LSource.Canvas.Pixels[0,0] := ABlendColor;
  AlphaBlend(Dest.canvas.handle, 0, 0, Dest.width, Dest.height, LSource.canvas.Handle, 0, 0, 1, 1, LBlendstruct);

  if GammaCorrection <> 0 then
  begin
    LSource.Canvas.Pixels[0,0] := clWhite;
    LBlendstruct.SourceConstantAlpha := GammaCorrection;
    AlphaBlend(Dest.canvas.handle, 0, 0, Dest.width, Dest.height, LSource.canvas.Handle, 0, 0, 1, 1, LBlendstruct);
  end;
  LSource.Free;
end;

supermuckl 13. Sep 2004 16:57

Re: Überblendung zweier Bitmaps
 
is das mit scanline nicht schneller ?!

//ups das is ja mit scanline *g* :duck:

Jörn 13. Sep 2004 17:08

Re: Überblendung zweier Bitmaps
 
http://www.efg2.com/Lab/
Da dürftest du fündig werden.

SirThornberry 13. Sep 2004 17:22

Re: Überblendung zweier Bitmaps
 
oder einfach mal ins msdn unter MSDN-Library durchsuchenalphablend schauen. Beispiel zur Anwendung dessen hab ich ja schon gepostet


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:08 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz