Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Watermark mit transparantem Text (https://www.delphipraxis.net/140030-watermark-mit-transparantem-text.html)

krzyk_91 10. Sep 2009 15:56


Watermark mit transparantem Text
 
Hallo zusmammen, ich möchte ein Programm schreiben, das Watermarks zu meinen Bildern zugibt. Ich habe einen Cod gefunden, der ermöglicht, den transparenten Text zu schreiben:

Delphi-Quellcode:
procedure Tform1.DrawTransparency(Canvas:TCanvas;X,Y:Integer ;Bitmap:TBitmap;Transparency:Byte);
var
Temp:TBitmap;
ByteSrc,ByteDest:^Byte;
TripleSrc,TripleDest:^TRGBTriple;
TransparentColor:TRGBTriple;
H,V:Integer;
begin
Bitmap.PixelFormat:=pf24bit;
Temp:=TBitmap.Create;
Temp.Canvas.Brush.Color :=Bitmap.TransparentColor;
Temp.Width :=Bitmap.Width ;
Temp.Height :=Bitmap.Height ;
Temp.PixelFormat:=pf24bit;
Temp.Canvas.CopyRect(Rect(0,0,Bitmap.Width ,Bitmap.Height ),Canvas,Rect(X,Y,Bitmap.Width+X ,Bitmap.Height+Y ));

if Bitmap.Transparent then
  begin


  TransparentColor.rgbtBlue :=(Bitmap.TransparentColor and $FF0000) shr 16 ;
  TransparentColor.rgbtGreen :=(Bitmap.TransparentColor and $00FF00) shr 8 ;
  TransparentColor.rgbtRed :=Bitmap.TransparentColor and $0000FF;

  Temp.TransparentColor :=Bitmap.TransparentColor;
  Temp.Transparent :=True;

for V:=0 to Bitmap.Height -1 do
  begin
    TripleSrc:=Bitmap.ScanLine[V];
     TripleDest:=Temp.ScanLine[V];
  for H:=0 to Bitmap.Width -1 do
      begin
     if(TransparentColor.rgbtBlue <> TripleSrc.rgbtBlue) or
       ( TransparentColor.rgbtGreen <> TripleSrc.rgbtGreen) or
       (TransparentColor.rgbtRed <> TripleSrc.rgbtRed ) then

          begin
          TripleDest^.rgbtBlue :=Trunc((TripleDest^.rgbtBlue / 100)*Transparency+
          (TripleSrc^.rgbtBlue / 100)*(100-Transparency));

          TripleDest^.rgbtGreen :=Trunc((TripleDest^.rgbtGreen / 100)*Transparency+
          (TripleSrc^.rgbtGreen / 100)*(100-Transparency));

          TripleDest^.rgbtRed :=Trunc((TripleDest^.rgbtRed / 100)*Transparency+
          (TripleSrc^.rgbtRed / 100)*(100-Transparency));
          end;

      inc(TripleSrc);
      inc(TripleDest);
     end ;
  end;
end
   else
begin
for V:=0 to Bitmap.Height -1 do
  begin
    ByteSrc:=Bitmap.ScanLine[V];
    ByteDest:=Temp.ScanLine[V];
  for H:=0 to Bitmap.Width*3 -1 do
    begin
    ByteDest^:=Trunc((ByteDest^ / 100)*Transparency+
    (ByteSrc^ / 100)*(100-Transparency));
    inc(ByteSrc);
    inc(ByteDest);
    end;
  end;
end;
  Canvas.Draw(X,Y,Temp);
  Temp.Free;
end;
und die Prozedur, die DrawTransparency ausruft:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
bmp : TBitmap;
const ZnakWodny ='aaaa';
begin

bmp := TBitmap.Create;
bmp.LoadFromFile('image1.bmp');

bmp.Canvas.Font.Size :=50;

bmp.Canvas.Font.Color:=$00FFFFFE;


bmp.Canvas.Font.Name:='Franklin Gothic Medium';
bmp.Width:= bmp.Canvas.TextWidth(ZnakWodny) ;
bmp.Height:= bmp.Canvas.TextHeight(ZnakWodny) ;
bmp.Canvas.TextOut(0,0,ZnakWodny);

bmp.TransparentColor :=clblack;


bmp.TransparentColor :=Clwhite;

bmp.Transparent := true;

DrawTransparency(image1.Canvas,0,0,bmp,50);


image1.Picture.SaveToFile('image1-watermark.bmp');
bmp.Free;

end;
Der Text ist transparent, aber sieht nicht zu gut aus. Die Kanten jeder Buchstabe ist scharf, sie sieht so aus, weil das Antialising nicht verwendet wurde.

Ich habe den Code von hier http://www.delphipraxis.net/internal...t=antialiasing bentutzt, habe so in Delphi geschrieben:

Delphi-Quellcode:
DrawTransparency(image1.Canvas,0,0,bmp,50);
 Antialiasing2(image1.Canvas,rect(0,0,100,100),40);
Jest ist die Textqualität viel besser, aber die Farbe ist schon nicht so schön weiß und transparent.Lass sich das irgendwie ändern. Ich möchte ein Programm haben, das solche Watermarks bildet, die in z. B. Photoshop zu bekommen sind. Danke im Voraus für Hilfer

Blup 11. Sep 2009 08:41

Re: Watermark mit transparantem Text
 
Ausgangspunkt ist eine Bitmap mit dem Bild und eine weitere mit der Schrift. Die Schriftbitmap enthält nur schwarze und weiße Punkte.
Damit die Ecken und Kanten der Schrift nicht zu hart sind, kann man auf diese Bitmap Antialiasing oder Blur anwenden. Danach sind auch mehr oder weniger graue Punkte vorhanden.
Im Prinzip ist die Schriftbitmap jetzt ein Alphakanal, der bestimmt wie stark das Bildbitmap an der entsprechenden Stelle durchscheinend ist. Der Faktor muss für jedes einzelne Pixel neu ermittelt werden.

Die Faktoren sind auf 0..1 zu skalieren.
Faktor = FesterFaktor * Helligkeit(SchriftPixel)

HintergrundFarbe ist in diesem Fall konstant weiß.
BildPixelFarbe = BildPixelFarbe * (1 - Faktor) + HintergrundFarbe * Faktor

krzyk_91 11. Sep 2009 14:28

Re: Watermark mit transparantem Text
 
Wie könnte ich das in Delphi machen??


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:10 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