各种函数的性能测试。哈哈不仅教了你StretchDIBit的用法,各种函数测试也帮你做!都是我自己原创,今天拿出来晒晒,中国加油,DELPHI FANS加油。
unit MainView;
// This code was generated by the EasyMVC OTA Wizard
// www.eazisoft.com
interface
uses
Windows, Messages, SysUtils, Classes,Graphics,DrawDib,
Controls,StdCtrls,ComCtrls,ExtCtrls,Forms,patterns, Menus;
type
TViewMain = class(TFORM,IObserver)
MainMenu1: TMainMenu;
N1: TMenuItem;
N_New: TMenuItem;
N3: TMenuItem;
N_Close: TMenuItem;
N5: TMenuItem;
N_Push: TMenuItem;
N_Wood: TMenuItem;
N_Pwindows: TMenuItem;
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
Image1: TImage;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
procedure UpdateView(o: TObject);
public
{ Public declarations }
procedure DirectDisplay(BmpFile : String; Handle : HDC);
procedure DirectDisplay2(BmpFile : String; Handle : HDC);
procedure DirectDisplay3(BmpFile : String; Handle : HDC);
procedure SetNotifyEventHandler(ANotifyEvent: TNotifyEvent);
end;
implementation
uses DHCtrl;
{$R *.dfm}
procedure TViewMain.UpdateView(o: TObject);
begin
end;
procedure TViewMain.SetNotifyEventHandler(ANotifyEvent: TNotifyEvent);
var
i : Integer ;
begin
for i := 0 to self.ComponentCount - 1 do
begin
if Components is TMenuItem then
(Components as TMenuItem).OnClick := ANotifyEvent;
end;
end;
procedure TViewMain.Button1Click(Sender: TObject);
var
bmp : TBitmap ;
i : Integer ;
Start : DWORD ;
begin
Bmp := TBitmap.Create ;
bmp.LoadFromFile('e:/1.bmp');
Start := GetTickCount ;
for i := 0 to 5000 do
begin
bmp.Canvas.TextOut(10,10,inttostr(i));
StretchBlt(self.Canvas.Handle, 10, 10, 320,240,bmp.Canvas.Handle,0,0,320,240,self.Canvas.CopyMode);
end;
Caption := IntToStr(GetTickCount - Start);
bmp.Free ;
end;
procedure TViewMain.Button2Click(Sender: TObject);
var
start : DWORD ;
i : Integer ;
begin
start := GetTickCount ;
DirectDisplay('e:/1.bmp',image1.Canvas.Handle);
Caption := IntToStr(GetTickCount - start) ;
end;
procedure TViewMain.DirectDisplay(BmpFile: String; Handle: HDC);
var
Bmf: TBitmapFileHeader;
BitmapInfo: PBitmapInfo;
HeaderSize: Integer;
ImageSize: LongWord;
BitsMem: Pointer;
Stream: TFileStream;
i : Integer ;
begin
try
Stream := TFileStream.Create(BmpFile, fmOpenRead or fmShareDenyWrite);
Stream.ReadBuffer(Bmf, sizeof(Bmf)); //¶ÁÎļþÍ·
ImageSize := Stream.Size - sizeof(Bmf) ;
Stream.ReadBuffer(HeaderSize, sizeof(HeaderSize));
GetMem(BitmapInfo, HeaderSize + 12 + 256 * sizeof(TRGBQuad));
Stream.ReadBuffer(Pointer(Longint(BitmapInfo) + sizeof(HeaderSize))^,
HeaderSize - sizeof(HeaderSize)); //¶ÁλͼÐÅÏ¢
BitmapInfo^.bmiHeader.biSize := HeaderSize ;
Dec(ImageSize, HeaderSize);
GetMem(BitsMem,ImageSize);
Stream.ReadBuffer(BitsMem^, ImageSize);
for i := 0 to 3000 do
begin
StretchDIBits( Handle,
0, 0,BitmapInfo^.bmiHeader.biWidth , BitmapInfo^.bmiHeader.biHeight,
0, 0, BitmapInfo^.bmiHeader.biWidth, BitmapInfo^.bmiHeader.biHeight,
BitsMem, BitmapInfo^, 0, SRCCOPY);
image1.Canvas.TextOut(10,10,inttostr(i));
Image1.Refresh ;
end;
finally
FreeMem(BitsMem);
Stream.Free ;
end;
end;
procedure TViewMain.DirectDisplay2(BmpFile: String; Handle: HDC);
var
Bmf: TBitmapFileHeader;
BitmapInfo: PBitmapInfo;
HeaderSize: Integer;
ImageSize: LongWord;
BitsMem: Pointer;
Stream: TFileStream;
HdcMem : HDC ;
HBit: hBitmap ;
i : Integer ;
begin
try
Stream := TFileStream.Create(BmpFile, fmOpenRead or fmShareDenyWrite);
Stream.ReadBuffer(Bmf, sizeof(Bmf)); //¶ÁÎļþÍ·
ImageSize := Stream.Size - sizeof(Bmf) ;
Stream.ReadBuffer(HeaderSize, sizeof(HeaderSize));
GetMem(BitmapInfo, HeaderSize + 12 + 256 * sizeof(TRGBQuad));
Stream.ReadBuffer(Pointer(Longint(BitmapInfo) + sizeof(HeaderSize))^,
HeaderSize - sizeof(HeaderSize)); //¶ÁλͼÐÅÏ¢
BitmapInfo^.bmiHeader.biSize := HeaderSize ;
Dec(ImageSize, HeaderSize);
GetMem(BitsMem,ImageSize);
Stream.ReadBuffer(BitsMem^, ImageSize);
HdcMem := CreateCompatibleDC( Handle ) ;
for i := 0 to 3000 do
begin
HBit := CreateDIBitmap(hdcMem,BitmapInfo^.bmiHeader,CBM_INIT,BitsMem,BitmapInfo^,DIB_RGB_COLORS);
SelectObject(hdcMem,HBit );
BitBlt(Handle,
0,0,BitmapInfo^.bmiHeader.biWidth,BitmapInfo^.bmiHeader.biHeight,
hdcMem,0,0,SrcCopy );
Image1.Canvas.TextOut(10,10,inttostr(i));
image1.Refresh ;
end;
finally
FreeMem(BitsMem);
Stream.Free ;
end;
end;
procedure TViewMain.Button3Click(Sender: TObject);
var
start : DWORD ;
i : Integer ;
begin
start := GetTickCount ;
DirectDisplay2('e:/1.bmp',image1.Canvas.Handle);
Caption := IntToStr(GetTickCount - start) ;
end;
procedure TViewMain.Button4Click(Sender: TObject);
var
start : DWORD ;
i : Integer ;
begin
start := GetTickCount ;
DirectDisplay3('e:/1.bmp',image1.Canvas.Handle);
Caption := IntToStr(GetTickCount - start) ;
end;
procedure TViewMain.DirectDisplay3(BmpFile: String; Handle: HDC);
var
Bmf: TBitmapFileHeader;
BitmapInfo: PBitmapInfo;
HeaderSize: Integer;
ImageSize: LongWord;
BitsMem: Pointer;
Stream: TFileStream;
hdd :THandle;
i : Integer ;
begin
try
Stream := TFileStream.Create(BmpFile, fmOpenRead or fmShareDenyWrite);
Stream.ReadBuffer(Bmf, sizeof(Bmf)); //¶ÁÎļþÍ·
ImageSize := Stream.Size - sizeof(Bmf) ;
Stream.ReadBuffer(HeaderSize, sizeof(HeaderSize));
GetMem(BitmapInfo, HeaderSize + 12 + 256 * sizeof(TRGBQuad));
Stream.ReadBuffer(Pointer(Longint(BitmapInfo) + sizeof(HeaderSize))^,
HeaderSize - sizeof(HeaderSize)); //¶ÁλͼÐÅÏ¢
BitmapInfo^.bmiHeader.biSize := HeaderSize ;
Dec(ImageSize, HeaderSize);
GetMem(BitsMem,ImageSize);
Stream.ReadBuffer(BitsMem^, ImageSize);
hdd := DrawDibOpen; //´ò¿ªDraw¾ä±ú
for i := 0 to 3000 do
begin
DrawDibDraw( hdd,Handle,
0, //ԭͼÏñ
0,
BitmapInfo^.bmiHeader.biWidth*2,
BitmapInfo^.bmiHeader.biHeight*2,
BitmapInfo^.bmiHeader, //ԭͼÏñÍ·ÐÅÏ¢½á¹¹
BitsMem, //ԭͼÏñÊý¾Ý
0, //ÏÔʾ
0,
BitmapInfo^.bmiHeader.biWidth,
BitmapInfo^.bmiHeader.biHeight,
DDF_SAME_HDC); //±êÖ¾
Image1.Canvas.TextOut(10,10,inttostr(i));
//image1.Refresh;
end;
finally
DrawDibClose(hdd);
FreeMem(BitsMem);
Stream.Free ;
end;
end;
end.
在我的笔记中,还有一个VFW的函数,我测下来效率与我给你的函数差不多。其实用这个函数还有一个原因,XVID解压出来的视频正好是这个函数的参数,我在开发机器上,测下来1秒钟解压带显示能跑到1500帧,呵呵,能满足要求了。当然机器也比较好。用VC2005编译的。到这里只能祝你好运了。