程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 更多關於編程 >> Delphi完成圖片轉動切換的完全實例代碼

Delphi完成圖片轉動切換的完全實例代碼

編輯:更多關於編程

Delphi完成圖片轉動切換的完全實例代碼。本站提示廣大學習愛好者:(Delphi完成圖片轉動切換的完全實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成圖片轉動切換的完全實例代碼正文


本文以實例引見了Delphi完成圖片轉動切換的辦法。該法式可以完成圖象的轉動播出,而且經由過程本代碼可掌握窗口中的圖象向上轉動,經由過程調理速度轉動條的值還可以調劑轉動的速度;點擊“停滯”按鈕,圖象即停滯轉動。

完全的功效代碼以下:

unit Unit1;
interface
uses
Windows, Classes, Graphics, Forms, Controls, Menus,
Dialogs, StdCtrls, ExtCtrls, SysUtils, ComCtrls, Buttons;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
AboutImageViewer1: TMenuItem;
OpenDialog1: TOpenDialog;
Options1: TMenuItem;
ColorDepth1: TMenuItem;
ScrollPanel1: TMenuItem;
Panel1: TPanel;
TrackBar1: TTrackBar;
BitBtn2: TBitBtn;
BitBtn1: TBitBtn;
Label1: TLabel;
Image1: TImage;
N2: TMenuItem;
procedure Open1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure AboutImageViewer1Click(Sender: TObject);
procedure ColorDepth1Click(Sender: TObject);
procedure ScrollPanel1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
nLines: Integer;
fCancel: Boolean;
implementation
{$R *.DFM}
procedure TForm1.Open1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Image1.Picture.LoadFromFile (OpenDialog1.FileName);//導入圖象文件
Caption := '掌握圖象靜態挪動- ' + OpenDialog1.FileName;//轉變窗體題目
end;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close; //加入窗體
end;
procedure TForm1.AboutImageViewer1Click(Sender: TObject);//關於
begin
MessageDlg ('掌握圖象靜態挪動為'+ #13'Delphi圖形任務室制造', mtInFormation,
[mbOk], 0);
end;
procedure TForm1.ColorDepth1Click(Sender: TObject);
var
strDepth: String;
begin
case Image1.Picture.Bitmap.PixelFormat of //取得圖象色彩深度
pfDevice: strDepth := '無圖';
pf1bit: strDepth := '1-bit';
pf4bit: strDepth := '4-bit';
pf8bit: strDepth := '8-bit';
pf15bit: strDepth := '15-bit';
pf16bit: strDepth := '16-bit';
pf24bit: strDepth := '24-bit';
pf32bit: strDepth := '32-bit';
pfCustom: strDepth := 'Custom';
end;
MessageDlg ('圖象色彩深度:' + strDepth,mtInFormation, [mbOK], 0);//給出圖象
色彩深度信息
end;
procedure TForm1.ScrollPanel1Click(Sender: TObject);
begin
Panel1.Visible := not Panel1.Visible;
ScrollPanel1.Checked := Panel1.Visible; //轉變掌握面板的可見性
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
nLines := TrackBar1.Position;
TrackBar1.Hint := IntToStr (TrackBar1.Position);//給出以後速度年夜小的提醒
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
W, H, I, J, LineBytes: Integer;
Line: PByteArray; //界說指針類型變量
Bmp: Tbitmap;
R: TRect;
begin
if Image1.Picture.Bitmap.PixelFormat=pfDevice then //當沒有翻開圖片時
begin
MessageDlg ('沒有翻開圖片!', mtInFormation, [mbOk], 0);//給出失足提醒
exit; //加入
end
else
fCancel := False;
BitBtn1.Enabled := False; //轉變兩個按鈕的屬性
BitBtn2.Enabled := True;
Bmp := Image1.Picture.Bitmap; //獲得BMP 圖象並界說圖象尺寸
W := Bmp.Width;
H := Bmp.Height;
LineBytes := Abs (Integer (Bmp.ScanLine [1]) -Integer (Bmp.ScanLine [0]));
Line := AllocMem (LineBytes);
for I := 0 to H - 1 do
begin
if fCancel then //在每次輪回前均檢討中止標記(即肯定停滯按鈕能否按下)
Break; //單擊“停滯”按鈕則停滯轉動圖象
Move ((Bmp.ScanLine [0]), Line, LineBytes); //復制圖象的第一行
for J := 1 to H - 1 do
begin
Move ((Bmp.ScanLine [J]), (Bmp.ScanLine [J-1]), LineBytes);
if (J mod nLines = 0) then
begin
R := Rect (0, Panel1.Height + J-nLines,W, Panel1.Height + J);
InvalidateRect (Handle, @R, False);
UpdateWindow (Handle);
end;
end;
Move (Line, (Bmp.ScanLine [Bmp.Height - 1]), LineBytes);
R := Rect (0, Panel1.Height + H - nLines,W, Panel1.Height + H);
InvalidateRect (Handle, @R, False);
UpdateWindow (Handle);
Application.ProcessMessages; //許可立刻停滯輪回使法式處於初始狀況
end;
BitBtn1.Enabled := True; //激活“開端”按鈕
BitBtn2.Enabled := False; // 停滯“按鈕”掉效
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
fCancel := True; //轉變標記Fcancel 的值,停滯圖象轉動
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TrackBar1Change (self); //挪用TrackBar1Change 函數
end;
end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved