⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usetpixel.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit USetPixel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  {erase the current image}
  Canvas.Brush.Color := Color;
  Canvas.FillRect(ClientRect);

  {begin the effect}
  Timer1.Enabled := TRUE;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  X, Y: Integer;       // tracks pixel coordinates
  iCount: Integer;     // a general loop counter
begin
  {begin the cheap fade effect}
  for iCount := 0 to 20000 do
  begin
    {retrieve a random coordinate}
    X := Random(Image1.Width-1);
    Y := Random(Image1.Height-1);

    {in a 4x4 pixel square at this coordinate, retrieve the pixels in the
     source image, and set them in the form's canvas}
    SetPixel(Canvas.Handle, X+Image1.Left, Y+Image1.Top,
             GetPixel(Image1.Picture.Bitmap.Canvas.Handle, X, Y));
    SetPixel(Canvas.Handle, X+1+Image1.Left, Y+Image1.Top,
             GetPixel(Image1.Picture.Bitmap.Canvas.Handle, X+1, Y));
    SetPixel(Canvas.Handle, X+Image1.Left, Y+1+Image1.Top,
             GetPixel(Image1.Picture.Bitmap.Canvas.Handle, X, Y+1));
    SetPixel(Canvas.Handle, X+1+Image1.Left, Y+1+Image1.Top,
             GetPixel(Image1.Picture.Bitmap.Canvas.Handle, X+1, Y+1));
  end;

  {draw the finished image so that there are no holes left}
  Canvas.Draw(Image1.Left, Image1.Top, Image1.Picture.Bitmap);

  {disable the timer}
  Timer1.Enabled := FALSE;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -