<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      基于Delphi的圖像漫游

      [摘要]在開發多媒體應用中,經常會遇到需要在有限區域內顯示大圖像 的情況,有不少文章對此提出過解決方法,如通過調用Windows的API函 數,直接讀寫內存等。這些方法有某些優點,但實現起來較為復雜,且 易...
      在開發多媒體應用中,經常會遇到需要在有限區域內顯示大圖像
      的情況,有不少文章對此提出過解決方法,如通過調用Windows的API函
      數,直接讀寫內存等。這些方法有某些優點,但實現起來較為復雜,且
      易出錯。筆者在實踐中通過仔細摸索,利用Delphi的強大的面向對象
      可視化開發環境開發了一種交互式圖像漫游方法。
      Delphi中,鼠標的消息響應是通過元件的OnMouseDown、OnMouseU
      p和OnMouseMove事件實現的,通過對此三個事件編程,可控制圖像在有
      限區域內移動?紤]到所移動的圖像的邊界應總在該區域外,因此圖
      像的左上角坐標應小于該區域對應坐標,圖像右下角坐標應大于該區
      域對應坐標(除非圖像大小比該區域小)。圖1
      具體方法是:
      1、新建一工程Project1,在Form1中依次放入Panel1、Panel2和I
      mage1元件,注意Pa nel2和Image1分別在Panel1和Panel2上,再將一La
      bel1元件加入Panel2中,調整Panel1尺寸為適當大小,并修改各元件屬
      性為:
      元件
      屬性名
      屬性值
      Panel1
      BevelInner:
      bvRaised
      BevelOuter: bvNone
      BorderStyle: bsSingle
      Panel2
      Align:
      alClient
      Image1
      AutoSize:
      True
      Picture:
      "Apple.bmp"
      Label1
      Align:
      alClient
      Transparent : True
      注意:此處Label1的作用不是顯示字符,而是利用它響應鼠標消息
      ,如果不用Label1而直接利用Image1的鼠標事件響應,則會由于其OnMo
      useDown事件的激活與Image1的自身坐標移動事件沖突而使圖像發生
      閃爍甚至不能移動。
      2、在implementation后加入變量聲明:
      origin:Tpoint;
      image_left:integer;
      image_top:integer;
      visa1:Tpoint; (鼠標當前位置相對圖像右下角的坐標)
      visa2:Tpoint; (鼠標當前位置相對圖像左上角的坐標)
      canmove:boolean;
      編寫Label1鼠標響應事件:
      procedure TForm1.Label1MouseDown(Sender: TObject; Button
      : TMouseButton;S hift: TShiftState; X, Y: Integer);
      begin
      if Button=mbLeft then
      begin
      origin.x:=X;
      origin.y:=Y;
      image_left:=image1.left;
      image_top:=image1.top;
      visa1.x:=X-(image1.width-panel2.width+image1.left);
      visa1.y:=Y-(image1.height-panel2.height+image1.top);
      visa2.x:=X-image1.left;
      visa2.y:=Y-image1.top;
      canmove:=true;
      end;
      end;
      procedure TForm1.Label1MouseMove(Sender: TObject; Shift:
      TShiftState; X, Y: Integer);
      begin
      if canmove then
      begin
      if X< visa1.x then X:=visa1.x;
      if X>visa2.x then X:=visa2.x;
      if Y< visa1.y then Y:=visa1.y;
      if Y>visa2.y then Y:=visa2.y;
      image1.left:=image_left+(X-origin.x);
      image1.top:=image_top+(Y-origin.y);
      end;
      end;
      procedure TForm1.Label1MouseUp(Sender: TObject; Button:
      TMouseButton;Shi ft: TShiftState; X, Y: Integer);
      begin
      canmove:=false;
      end;
      上述程序在Delphi 2.0中編譯通過,經過擴充和修改還可應用于
      多媒體數據庫的圖像顯示,對于開發友好界面有一定借鑒作用。


      日韩精品一区二区三区高清