欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

照片拼接效果的火喉代码实现(firemonkey)

程序员文章站 2024-03-19 18:23:10
...

结果:

      照片拼接效果的火喉代码实现(firemonkey)

代码链接:

 

链接:https://pan.baidu.com/s/135lyyAQw4MmbUTD69-qUyQ 
提取码:lmpo 

缘起:

在抖音中看到有小盆友使用ps来实现照片拼接效果,顿生一个念头:是不是可以使用firemonkey技术来实现,浅浅地试了一下,居然成功了。

思路如下:

     1、使用multidevice窗体。

     2、使用Layout衬底,放置Rectangle作为画布载入照片,在它上面放置4个Rectangle并动态加载画框gif照片(注意画框当中要镂空)。

     3、使用cnwizard生成代码即可:

var
  Form1: TForm1;
  icount: Integer;

implementation

{$R *.fmx}

procedure TForm1.Action1Execute(Sender: TObject);
begin
  Self.CornerButton2.Visible := False;
  CornerButton2Click(Self);
end;

procedure TForm1.Action2Execute(Sender: TObject);
begin
  CornerButton1Click(self);
end;

procedure TForm1.CornerButton1Click(Sender: TObject);
var
  Rectangle1: TRectangle;
  Rectangle2: TRectangle;
  Rectangle3: TRectangle;
  Rectangle4: TRectangle;
  Rectangle5: TRectangle;
  ShadowEffect2: TShadowEffect;
  ShadowEffect3: TShadowEffect;
  ShadowEffect4: TShadowEffect;
  ShadowEffect5: TShadowEffect;
begin

  case icount of
    0:

      begin

        Rectangle2 := TRectangle.Create(Self);
        Rectangle2.Name := 'Rectangle2';
        Rectangle2.Parent := layout1;
        Rectangle2.Fill.Kind := TBrushKind.Bitmap;
        Rectangle2.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
        Rectangle2.Fill.Bitmap.Bitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'xk.gif');
        Rectangle2.Opacity := 1.000000000000000000;
        Rectangle2.Position.X := 128.000000000000000000;
        Rectangle2.Position.Y := 88.000000000000000000;
        Rectangle2.RotationAngle := 10.000000000000000000;
        Rectangle2.Size.Width := 201.000000000000000000;
        Rectangle2.Size.Height := 161.000000000000000000;
        Rectangle2.Size.PlatformDefault := False;

        ShadowEffect2 := TShadowEffect.Create(Self);
        ShadowEffect2.Name := 'ShadowEffect2';
        ShadowEffect2.Distance := 3.000000000000000000;
        ShadowEffect2.Direction := 45.000000000000000000;
        ShadowEffect2.Softness := 0.300000011920929000;
        ShadowEffect2.Opacity := 0.600000023841857900;
        ShadowEffect2.ShadowColor := TAlphaColorRec.Black;
        ShadowEffect2.Parent := Rectangle2;

      end;
    1:
      begin

        Rectangle3 := TRectangle.Create(Self);
        Rectangle3.Name := 'Rectangle3';
        Rectangle3.Parent := layout1;
        Rectangle3.Fill.Kind := TBrushKind.Bitmap;
        Rectangle3.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
        Rectangle3.Fill.Bitmap.Bitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'xk2.gif');
        Rectangle3.Opacity := 1.000000000000000000;
        Rectangle3.Position.X := 264.000000000000000000;
        Rectangle3.Position.Y := 32.000000000000000000;
        Rectangle3.RotationAngle := -10.000000000000000000;
        Rectangle3.Size.Width := 225.000000000000000000;
        Rectangle3.Size.Height := 177.000000000000000000;
        Rectangle3.Size.PlatformDefault := False;

        ShadowEffect3 := TShadowEffect.Create(Self);
        ShadowEffect3.Name := 'ShadowEffect3';
        ShadowEffect3.Distance := 3.000000000000000000;
        ShadowEffect3.Direction := 45.000000000000000000;
        ShadowEffect3.Softness := 0.300000011920929000;
        ShadowEffect3.Opacity := 0.600000023841857900;
        ShadowEffect3.ShadowColor := TAlphaColorRec.Black;
        ShadowEffect3.Parent := Rectangle3;
      end;
    2:
      begin

        Rectangle4 := TRectangle.Create(Self);
        Rectangle4.Name := 'Rectangle4';
        Rectangle4.Parent := layout1;
        Rectangle4.Fill.Kind := TBrushKind.Bitmap;
        Rectangle4.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
        Rectangle4.Fill.Bitmap.Bitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'xkxk.gif');
        Rectangle4.Opacity := 1.000000000000000000;
        Rectangle4.Position.X := 184.000000000000000000;
        Rectangle4.Position.Y := 168.000000000000000000;
        Rectangle4.RotationAngle := 120.000000000000000000;
        Rectangle4.Size.Width := 241.000000000000000000;
        Rectangle4.Size.Height := 193.000000000000000000;
        Rectangle4.Size.PlatformDefault := False;

        ShadowEffect4 := TShadowEffect.Create(Self);
        ShadowEffect4.Name := 'ShadowEffect4';
        ShadowEffect4.Distance := 3.000000000000000000;
        ShadowEffect4.Direction := 45.000000000000000000;
        ShadowEffect4.Softness := 0.300000011920929000;
        ShadowEffect4.Opacity := 0.600000023841857900;
        ShadowEffect4.ShadowColor := TAlphaColorRec.Black;
        ShadowEffect4.Parent := Rectangle4;

      end;

    3:
      begin
        Rectangle5 := TRectangle.Create(Self);
        Rectangle5.Name := 'Rectangle5';
        Rectangle5.Parent := layout1;
        Rectangle5.Fill.Kind := TBrushKind.Bitmap;
        Rectangle5.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
        Rectangle5.Fill.Bitmap.Bitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'xkxkxk.gif');
        Rectangle5.Position.X := 360.000000000000000000;
        Rectangle5.Position.Y := 144.000000000000000000;
        Rectangle5.RotationAngle := 60.000000000000000000;
        Rectangle5.Size.Width := 217.000000000000000000;
        Rectangle5.Size.Height := 225.000000000000000000;
        Rectangle5.Size.PlatformDefault := False;
        Rectangle5.Opacity := 1.000000000000000000;

        ShadowEffect5 := TShadowEffect.Create(Self);
        ShadowEffect5.Name := 'ShadowEffect5';
        ShadowEffect5.Distance := 3.000000000000000000;
        ShadowEffect5.Direction := 45.000000000000000000;
        ShadowEffect5.Softness := 0.300000011920929000;
        ShadowEffect5.Opacity := 0.600000023841857900;
        ShadowEffect5.ShadowColor := TAlphaColorRec.Black;
        ShadowEffect5.Parent := Rectangle5;
      end;
    4:
      icount := 0;
  end;
  Inc(icount);
end;

procedure TForm1.CornerButton2Click(Sender: TObject);
begin
  Self.CornerButton1.Visible := False;
  Layout1.MakeScreenshot.SaveToFile('d:\potoframe.png');

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  self.Rectangle1.Fill.Bitmap.Bitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'bg.jpg');
end;

代码截图输出效果:

照片拼接效果的火喉代码实现(firemonkey)