FireMonkey 入门(16) - 滤镜: 实例测试

减小字体 增大字体 作者:佚名  来源:万一的博客  发布时间:2011-10-20 12:31:17

窗体上需要 TImage、TOpenDialog 和六个按钮.

 
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects;

type
  TForm1 = class(TForm)
    Image1: TImage;
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

uses FMX.Filter;

var
  bit: TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bit := TBitmap.Create(0, 0);
  if not OpenDialog1.Execute then Exit;
  bit.LoadFromFile(OpenDialog1.FileName);
  Image1.Bitmap.Assign(bit);
  Image1.SetBounds(10, 10, bit.Width, bit.Height);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bit.Free;
end;

{高斯模糊: 一个参数}
procedure TForm1.Button1Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('GaussianBlur');           //GaussianBlur 是高斯模糊滤镜的名称
  filter.Values['BlurAmount'] := 0.25;              //BlurAmount 是高斯模糊参数的名称, 默认值是 1(0.1..10)
  filter.ValuesAsBitmap['input'] := bit;            //input  是给输入图片约定的索引名称, 不区分大小写
  Image1.Bitmap := filter.ValuesAsBitmap['output']; //output 是给输出图片约定的索引名称
end;

{颜色翻转: 无参数}
procedure TForm1.Button2Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('Invert');       //颜色翻转
  filter.ValuesAsBitmap['input'] := bit;
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
end;

{灰度: 无参数}
procedure TForm1.Button3Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('Monochrome');
  filter.ValuesAsBitmap['input'] := bit;
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
end;

{马赛克: 一个参数}
procedure TForm1.Button4Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('Pixelate');
  filter.Values['BlockCount'] := 30; {25 : 1..1000}
  filter.ValuesAsBitmap['input'] := bit;
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
end;

{对比度: 两个参数}
procedure TForm1.Button5Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('Contrast');
  filter.Values['Brightness'] := -0.5; {-1..1}
  filter.Values['Contrast']   := 1.5;  {0..2}
  filter.ValuesAsBitmap['input'] := bit;
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
end;

{透视: 参数是四个点}
procedure TForm1.Button6Click(Sender: TObject);
var
  filter: TFilter;
begin
  filter := FilterByName('PerspectiveTransform');
  filter.Values['TopLeft'] := VarFromPointXY(0, 0);
  filter.Values['TopRight'] := VarFromPointXY(bit.Width, 0);
  filter.Values['BottomRight'] := VarFromPointXY(bit.Width * 2, bit.Height * 2);
  filter.Values['BottomLeft'] := VarFromPointXY(0, bit.Height);
  filter.ValuesAsBitmap['input'] := bit;
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
  Image1.SetBounds(10, 10, bit.Width * 2, bit.Height * 2);
end;

end.

Transition 分类的滤镜需要两张图片:

uses FMX.Filter;

var
  bit1,bit2: TBitmap;

{百叶窗效果}
procedure TForm1.FormCreate(Sender: TObject);
var
  filter: TFilter;
begin
  bit1 := TBitmap.Create(0, 0);
  bit2 := TBitmap.Create(0, 0);
  bit1.LoadFromFile('C:\Temp\test1.jpg');
  bit2.LoadFromFile('C:\Temp\test2.jpg');

  filter := FilterByName('BlindTransition');
  filter.Values['Progress'] := 50;       //变换进度: 0..100; 当以此进度做动画时, PropertyName := 'Value'
  filter.Values['NumberOfBlinds'] := 10; //分叶数: 2..15

  filter.ValuesAsBitmap['input'] := bit1;
  filter.ValuesAsBitmap['target'] := bit2; //target 也是约定的索引名称
  Image1.Bitmap := filter.ValuesAsBitmap['output'];
  Image1.SetBounds(10, 10, bit1.Width, bit1.Height);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bit1.Free;
  bit2.Free;
end;
 

Tags:

作者:佚名
  • 好的评价 如果您觉得此文章好,就请您
      0%(0)
  • 差的评价 如果您觉得此文章差,就请您
      0%(0)

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

广告位置B