程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
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