Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Bildereffekt (https://www.delphipraxis.net/21463-bildereffekt.html)

S2B 3. Mai 2004 14:03


Bildereffekt
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi @all,
ich möchte ein Programm schreiben, das folgenden Effekt zu einem Bild hinzufügt (Bild im Anhang).

Zuerst möchte ich den Effekt nur anzeigen lassen und dann mit einem Speichern-Button in die Datei schreiben! Ich hab schon mitgekriegt, dass man das irgendwie mit DirectX machen kann, hab aber keinen Schimmer, wie ich das machen soll... :gruebel: Hab nämlich noch nichts mir DirectX gemacht!

Also, hoffe ihr könnt mir helfen!

Phantom1 3. Mai 2004 15:30

Re: Bildereffekt
 
Sieht nach einen einfachen Blureffekt aus. Ich habe dafür schon vor einiger Zeit mal eine Procedure geschrieben (geschwindigkeitsoptimiert), du kannst sie ja mal probieren:

Delphi-Quellcode:
procedure BmpGBlur(Bmp: TBitmap; radius: Single);
Type
  TRGB     = Packed Record b, g, r: Byte End;
  TRGBs    = Packed Record b, g, r: Single End;
  TRGBArray = Array[0..0] of TRGB;
Const
  ZeroTRGBs: TRGBs=(b:0; g:0; r:0);
Var
  MatrixRadius: Byte;
  Matrix : Array[-100..100] of Single;

  Procedure CalculateMatrix;
  Var x: Integer; Divisor: Single;
  Begin
    radius:=radius+1; // der mittel/nullpunkt muss mitgerechnet werden
    MatrixRadius:=Trunc(radius);
    If Frac(radius)=0 Then Dec(MatrixRadius);
    Divisor:=0;
    For x:=-MatrixRadius To MatrixRadius Do Begin
      Matrix[x]:=radius-abs(x);
      Divisor:=Divisor+Matrix[x];
    End;
    For x:=-MatrixRadius To MatrixRadius Do
      Matrix[x]:=Matrix[x]/Divisor;
  End;

Var
  BmpSL             : ^TRGBArray;
  BmpRGB            : ^TRGB;
  BmpCopy           : Array of Array of TRGBs;
  BmpCopyRGBs        : ^TRGBs;
  PixelRGBs         : TRGBs;
  BmpWidth, BmpHeight: Integer;
  x, y, mx          : Integer;
Begin
  Bmp.PixelFormat:=pf24bit;
  If radius<=0 Then radius:=1 Else If radius>99 Then radius:=99; // radius bereich 0 < radius < 99
  CalculateMatrix;
  BmpWidth:=Bmp.Width;
  BmpHeight:=Bmp.Height;
  SetLength(BmpCopy,BmpHeight,BmpWidth);
  // Alle Bildpunkte ins BmpCopy-Array schreiben und gleichzeitig HORIZONTAL blurren
  For y:=0 To Pred(BmpHeight) Do Begin
    BmpSL:=Bmp.Scanline[y];
    BmpCopyRGBs:=@BmpCopy[y,0];
    For x:=0 to Pred(BmpWidth) Do Begin
      BmpCopyRGBs^:=ZeroTRGBs;
      For mx:=-MatrixRadius To MatrixRadius Do Begin
        If x+mx<=0 Then
          BmpRGB:=@BmpSL^[0]             // erster Pixel
        Else If x+mx>=BmpWidth Then
          BmpRGB:=@BmpSL^[Pred(BmpWidth)] // letzter Pixel
        Else
          BmpRGB:=@BmpSL^[x+mx];
        BmpCopyRGBs^.b:=BmpCopyRGBs^.b+BmpRGB^.b*Matrix[mx];
        BmpCopyRGBs^.g:=BmpCopyRGBs^.g+BmpRGB^.g*Matrix[mx];
        BmpCopyRGBs^.r:=BmpCopyRGBs^.r+BmpRGB^.r*Matrix[mx];
      End;
      Inc(BmpCopyRGBs);
    End;
  End;
  // Alle Bildpunkte zurück ins Bmp-Bitmap schreiben und gleichzeitig VERTIKAL blurren
  For y:=0 To Pred(BmpHeight) Do Begin
    BmpRGB:=Bmp.ScanLine[y];
    For x:=0 to Pred(BmpWidth) Do Begin
      PixelRGBs:=ZeroTRGBs;
      For mx:=-MatrixRadius To MatrixRadius Do Begin
        If y+mx<=0 Then
          BmpCopyRGBs:=@BmpCopy[0,x]               // erster Pixel
        Else If y+mx>=BmpHeight Then
          BmpCopyRGBs:=@BmpCopy[Pred(BmpHeight),x] // letzter Pixel
        Else
          BmpCopyRGBs:=@BmpCopy[y+mx,x];
        PixelRGBs.b:=PixelRGBs.b+BmpCopyRGBs^.b*Matrix[mx];
        PixelRGBs.g:=PixelRGBs.g+BmpCopyRGBs^.g*Matrix[mx];
        PixelRGBs.r:=PixelRGBs.r+BmpCopyRGBs^.r*Matrix[mx];
      End;
      BmpRGB^.b:=Round(PixelRGBs.b);
      BmpRGB^.g:=Round(PixelRGBs.g);
      BmpRGB^.r:=Round(PixelRGBs.r);
      Inc(BmpRGB);
    End;
  End;
End;
Wenn du ein normales Image benutzt müsste es so gehen: BmpGBlur(Image1.Picture.Bitmap, 1.0);
Mit radius ist übrigens der Pixelradius gemeint, je größer der ist um so mehr wird geblurrt. Normal ist so 0.5 bis 5.0

S2B 3. Mai 2004 15:42

Re: Bildereffekt
 
Cool! Es geht! Danke! Jetzt hab ich nur noch 1 Problem:
Ich wollte noch den Rand des Bildes so in die Form übergehen lassen!

Gandalfus 3. Mai 2004 16:10

Re: Bildereffekt
 
also Alphablending?

S2B 3. Mai 2004 16:20

Re: Bildereffekt
 
Könnte man so sagen...
Edit: Meintest du mit dem Kommentar etwa sowas?

S2B 4. Mai 2004 13:27

Re: Bildereffekt
 
Hätte da einer eine Idee, wie man den Code nur am Rand und so abgestuft verwenden könnte?

S2B 5. Mai 2004 16:22

Re: Bildereffekt
 
Hat denn keiner eine Idee, wie man das umsetzen könnte?

shmia 5. Mai 2004 16:37

Re: Bildereffekt
 
Zitat:

Zitat von S2B
Hätte da einer eine Idee, wie man den Code nur am Rand und so abgestuft verwenden könnte?

Ist doch nicht so schwer: :shock:
1.) Auf das Bild einen weissen Rahmen zeichnen; dabei werden einige Pixel des Bildes am Rand
mit Weiß überschrieben.
2.) Bild unscharf machen (Blur-Effekt)

Sebastian Nintemann 5. Mai 2004 16:38

Re: Bildereffekt
 
Hallo S2B, wie meinst du denn
Zitat:

nur am Rand und so abgestuft verwenden
?

Falls du so einen Effekt meinst wie auf deinem geposteten Bild, also dass von der Hintergrundfarbe am Rand so in das Bild geblendet wird, dann versuch doch folgendes:
Du vergrößerst dein Bild zu jeder Seite um eine bestimmte Anzahl von Pixeln, und füllst diesen Rand mit der Hintergrundfarbe. Danach wendest du die Prozedur von Phantom1 auf das Bitmap an. So sollte es einen weichen Übergang von der Hintergrundfarbe auf das eigentliche Bild geben (welches dann ja auch weichgezeichnet ist).

Viele Grüße, Sebastian

S2B 5. Mai 2004 17:01

Re: Bildereffekt
 
Wie kann man den Rahmen zeichnen? Ich hab nämlich keinen Schimmer! :oops:


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:16 Uhr.
Seite 1 von 2  1 2      

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