当前位置:主页>销售管理软件> 列表

如何随意显示Image的部分图片? 找管家婆软件教程

财务软件版1楼: 如何随意显示Image的部分图片?
就是说Image中的图片正常是Height:100,Width:20,图片中有1,2,3,4,5,上下衔接起来的
如果把Image.Height=20,只能显示出1,
如何做到随意显示呢?比如我要显示4,要如何处理呢?谢谢!

2楼: type
TForm1 = class(TForm)
Image1: TImage;
private
DupBmp:TBitmap;
public
procedure DuplicateImage(Image:TImage);
procedure ShowPictureByIndex(index:integer;W:integer=20;H:integer=20);
end;

implementation

procedure TForm1.DuplicateImage(Image: TImage);
begin
if not Assigned(DupBmp) then
begin
DupBmp:=TBitmap.Create;
DupBmp.Assign(Image1.Picture.Bitmap);
end;
end;

procedure TForm1.ShowPictureByIndex(index,W,H:integer);
var
Bmp:TBitmap;
begin // Index=1..5
DuplicateImage(Image1); // 保留原始图形
if not(Index in [1..5]) then index:=1; // 保证输入的索引正常
Bmp:=TBitmap.Create;
try
Bmp.Width:=W;
Bmp.Height:=H;
Bmp.Canvas.CopyRect(DupBmp.Canvas,Rect(0,(Index-1)*H,W,((Index-1)*H)+H));
Image1.Picture.Bitmap.Assign(Bmp);
finally
Bmp.Free;
Image1.Refresh;
end;
end; 如管家婆软件教程

3楼: 我看到ttplayer的皮肤图片就是这样的功能,例如关闭按钮图片就是一张,可以分为4个区域,分别是4个状态下的样子。
方法不知道,我是菜菜

4楼: 上面代码有问题,CopyRect参数不对
图片中没有索引啊,就是一个图片而已啊,
只是里面的图片可以切成五张

5楼: 這樣改
Bmp.Canvas.CopyRect(Rect(0,0,bmp.Width,Bmp.Height),DupBmp.Canvas,Rect(0,(Index-1)*H,W,((Index-1)*H)+H));
然後類似如下調用
ShowPictureByIndex(1,20,20),

6楼: 基本实现了,但如果要实现滑动的效果需要如何改啊?
比如有1->4,实现从1->2->3->4的滑动效果啊?谢谢

财务软件版7楼: 靠!自己动动小脑!平滑滚动你要用定时器并逐步变化扫描行,一帧帧地变我上面代码就
可以了,你只要用个定时器不断调用就可以了。给了你代码你都弄不懂,还怎么玩啊?

8楼: 呵呵。。小雨哥,别动气,比较菜

9楼: 呵呵,看到你看着代码都搞不清的样子,我是连代码都不敢写给你了,好好的代码,到了


你手里不知会变出什么问题,这是最后一次,以后我是再也不敢没弄清编程能力就写代码
了。

下面我帖的是完整的一个平滑滚动代码,是最最最最简单的了,你再弄不好,我也没法子
了,写这个代码时,我是把你的编程能力都考虑进去了:

unit Unit1;

interface

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

type
TDirParam=(dpTop,dpBottom,dpRight,dpLeft);
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
DupBmp:TBitmap;
Bmp:TBitmap;
OldTop,OldLeft:integer;
ImageW,ImageH:integer;
Dir:TDirParam;
Speed:integer;
NoBusy:Boolean;
procedure InitParam;
procedure DuplicateImage(Image:TImage);
procedure Start;
public
{ Public declarations }


end;

var
Form1: TForm1;

implementation

{$R *.dfm}

// 警告:Image1 中只能装入 BMP 格式的图片
procedure TForm1.InitParam;
begin // 初始化参数
OldTop:=0;OldLeft:=0;
ImageW:=Image1.Picture.Bitmap.Width;
ImageH:=Image1.Picture.Bitmap.Height div 5;
Dir:=dpTop; // 平滑滚动的方向
Speed:=1; // 平滑滚动的速度
if not Assigned(Bmp) then
Bmp:=TBitmap.Create;
Bmp.Width:=ImageW;
Bmp.Height:=ImageH;
Bmp.PixelFormat:=pf32Bit;
end;

procedure TForm1.DuplicateImage(Image: TImage);
begin // 保存原始图片
if not Assigned(DupBmp) then
begin
DupBmp:=TBitmap.Create;
DupBmp.Assign(Image1.Picture.Bitmap);
DupBmp.PixelFormat:=pf32bit;
Image.AutoSize:=False;
Image.SetBounds(0,0,ImageW,ImageH);
end;
end;

procedure TForm1.Start;
type // 平滑滚动计算
TRGBQuadarray = array[0..0] of TRGBQuad;
pRGBQuadArray = ^TRGBQuadArray;
var
A,B:pRGBQuadArray;
n,m:integer;


begin
if not NoBusy then exit;
NoBusy:=False;
case Dir of // 维度限制计算
dpTop:if (OldTop+ImageH)>DupBmp.Height then OldTop:=DupBmp.Height-ImageH;
dpBottom:if OldTop<0 then OldTop:=0;
dpLeft:if (OldLeft+ImageW)>DupBmp.Width then OldLeft:=DupBmp.Width-ImageW;
dpRight:if OldLeft<0 then OldLeft:=0;
end;

for n:=OldTop to OldTop+ImageH-1 do
begin
A := DupBmp.ScanLine[n];
B := Bmp.ScanLine[n-OldTop];
for m:=OldLeft to OldLeft+ImageW-1 do
B^[m-OldLeft]:=A^[m];
end;

Image1.Picture.Bitmap.Assign(Bmp);
Image1.Refresh; // 刷新
Application.ProcessMessages;

case Dir of // 增减维度计算
dpTop:Inc(OldTop,Speed);
dpBottom:Dec(OldTop,Speed);
dpLeft:Dec(OldLeft,Speed);
dpRight:Inc(OldLeft,Speed);
end;
NoBusy:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin // 定时器
if NoBusy then Start;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin // 开始
InitParam;
DuplicateImage(Image1);
NoBusy:=True;
Timer1.Interval:=100;
Timer1.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin // 停止
Timer1.Enabled:=False;
NoBusy:=False;
Image1.Picture.Assign(DupBmp);
Image1.AutoSize:=True;
InitParam;
end;

end.

10楼: 谢谢了,因以前一直在处理数据库方面的编程!对其它方面的好陌生