BGRABitmap图像操作3:用鼠标在窗体画连续的曲线

翻译 2016年08月31日 15:10:56


    


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  BGRABitmap, BGRABitmapTypes;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
    image: TBGRABitmap;
    mouseDrawing: boolean;
    mouseOrigin: TPoint;

    procedure DrawBrush(X, Y: Integer; Closed: Boolean);
    procedure PaintImage;

  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  image := TBGRABitmap.Create(640,480,BGRAWhite);  //create a 640x480 image
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
  begin
    mouseDrawing := True;
    mouseOrigin := Point(X,Y);
    DrawBrush(X,Y,True);        //   or   DrawBrush(X,Y);
  end;


end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if mouseDrawing then DrawBrush(X,Y,False);


end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
    mouseDrawing := False;

end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  PaintImage;
end;

procedure TForm1.PaintImage;
begin
  image.Draw(Canvas,0,0,True);
end;

procedure TForm1.DrawBrush(X, Y: Integer; Closed: Boolean);
const brushRadius = 20;
begin
  image.DrawLineAntialias(X,Y,mouseOrigin.X,mouseOrigin.Y,BGRA(0,0,0,128),brushRadius,Closed);
  mouseOrigin := Point(X,Y);

  PaintImage;
end;


end.


相关文章推荐

【Java Opencv系列】4.2在窗体中显示图像

4.2在窗体中显示图像 本节内容代码下载链接:http://download.csdn.net/detail/u012343179/9797262 在testOpencv项目的imageIO包...

4.2在窗体中显示图像

  • 2017-03-29 09:37
  • 16KB
  • 下载

BGRABitmap图像操作10:透视映射

透视映射允许改变每一个点的深度。 unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil,...

BGRABitmap图像操作5:画出月亮、太阳、灯光

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Gr...

BGRABitmap图像操作9e:用阈值制作雪上印迹纹理

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Gr...

BGRABitmap图像操作8:轴向的木质纹理

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Gr...

BGRABitmap图像操作9b:巧克力纹理背景

unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Gr...

BGRABitmap图像操作9d:渲染前面的水纹

水波随鼠标而动。      unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileU...

BGRABitmap图像操作9c:同时使用莫林杂点和 phong 阴影制作纹理

纹理随鼠标不停变化,有点像水面。
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)