如何把大图打开分成小图?用于拚图(100分)

  • 主题发起人 主题发起人 阿吉
  • 开始时间 开始时间

阿吉

Unregistered / Unconfirmed
GUEST, unregistred user!
我就是做不来!谁要有拚图源码,该我看一下
还有,在文本框怎样才能使录入的字对右?

请教各位高手
 
// try this one

unit Unit4;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure FromBigToSmall(strSourceBitmapFile:string; smallWidth,smallHeight:integer);
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
FromBigToSmall('testprint.bmp',300,300);
end;

procedure TForm1.FromBigToSmall(strSourceBitmapFile:string; smallWidth,smallHeight:integer);
var
srcBitmap, destBitmap:TBitmap;
nHorz,nVert : integer;
i,j : integer;
rectDraw : TRect;
begin
// 读取原始位图到srcBitmap, 建立小的位图对象
srcBitmap := TBitmap.Create;
srcBitmap.LoadFromFile(strSourceBitmapFile);
destBitmap := TBitmap.Create;
destBitmap.Width := smallWidth;
destBitmap.Height := smallHeight;
with rectDraw do
begin
left := 0;
top := 0;
right := smallWidth;
bottom := smallheight;
end;


// 计算横向和纵向分割的块数
nHorz := (srcBitmap.Width-1) div smallWidth;
nVert := (srcBitmap.Height-1) div smallHeight;

// 将原始bitmap分割的小块重新绘制在destBitmap,并加以保存
try
for i:= 0 to nHorz do
for j:= 0 to nVert do
begin
destBitmap.Canvas.FillRect(rectDraw);
destBitmap.Canvas.Draw(i*(-1)*smallWidth,j*(-1)*smallHeight,srcBitmap);
destBitmap.SaveToFile('temp'+inttostr(i*(nVert+1)+j)+'.bmp');
end;
finally
srcBitmap.Free;
destBitmap.Free;
end;

end;

end.
 
for i:= 0 to Rows - 1 do
for j:= 0 to Cols - 1 do begin
Bmp.Canvas.CopyRect(
Bmp.Canvas.ClipRect,
SourceBitmap.Canvas,
Rect(i * Bmp.Width, j * Bmp.Height, (i + 1) * Bmp.Width, (j + 1) * Bmp.Height));
Bmp.SaveToFile(Format('Bmp%s.bmp',
[FormatFloat('00000', i * Cols + j)]));
end;
 
你不会是要把图切成不规则形状吧
2)用单行的memo或者第3方控件 vc.vclxx.org上很多。
 
多人接受答案了。
 
后退
顶部