问题来源: http://www.cnblogs.com/del/archive/2009/01/30/1381263.html#1439476
这个例子是把一张图片平均分成了 4 份, 顺序是: 左、右、上、下; 没使用循环操作, 显得有点笨, 但容易理解.
这个例子是把一张图片平均分成了 4 份, 顺序是: 左、右、上、下; 没使用循环操作, 显得有点笨, 但容易理解.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const path = 'c:\temp\test.bmp'; {先准备好测试图片} var bit: TBitmap; bits: array[0..3] of TBitmap; {假如分成 4 份} i,w,h: Integer; begin bit := TBitmap.Create; bit.LoadFromFile(path); w := bit.Width div 2; h := bit.Height div 2; for i := 0 to 3 do begin bits[i] := TBitmap.Create; bits[i].SetSize(w, h); end; BitBlt(bits[0].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(bits[1].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, w, 0, SRCCOPY); BitBlt(bits[2].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, 0, h, SRCCOPY); BitBlt(bits[3].Canvas.Handle, 0, 0, w, h, bit.Canvas.Handle, w, h, SRCCOPY); for i := 0 to 3 do begin bits[i].SaveToFile(ChangeFileExt(path, Format('.%.3d.bmp', [i+1]))); bits[i].Free; end; bit.Free; end; end.