Dephi实现屏幕录像Word文档格式.docx
《Dephi实现屏幕录像Word文档格式.docx》由会员分享,可在线阅读,更多相关《Dephi实现屏幕录像Word文档格式.docx(14页珍藏版)》请在冰点文库上搜索。
![Dephi实现屏幕录像Word文档格式.docx](https://file1.bingdoc.com/fileroot1/2023-5/9/27b6e759-d71d-4ee9-9c7f-73d30e79d1c8/27b6e759-d71d-4ee9-9c7f-73d30e79d1c81.gif)
//BMP文件存储路径procedureTForm
1.FormCreate(Sender:
TObject);
begin
PicIndex:
=0;
BmpFileName:
='
'
;
ScreenBmp:
=TBitmap.Create;
ScreenBmp.PixelFormat:
=pf24bit;
ScreenBmp.Width:
=Screen.Width;
ScreenBmp.Height:
=Screen.Height;
ScreenBmp.Canvas.Brush.Style:
=bsClear;
RecPause:
=False;
//不录制透明窗体
RecTransFlag:
=SRCCOPY;
//录制透明窗体
//RecTransFlag:
=SRCCOPYorCAPTUREBLT;
AppPath:
=ExtractFilePath(Application.ExeName);
TempPath:
=AppPath+'
Temp\'
ifnotDirectoryExists(TempPath)then
CreateDirectory(PAnsiChar(TempPath),nil);
end;
procedureTForm
1.DrawCursorToBmp(varScrBmp:
TBitmap);
hCur:
HICON;
MousePt:
TPoint;
ifnotAssigned(ScrBmp)then
Exit;
=GetCursor();
GetCursorPos(MousePt);
//画光标
DrawIcon(ScrBmp.canvas.handle,MousePt.x,MousePt.y,hCur);
1.Timer1Timer(Sender:
dc:
HDC;
DC:
=GetDC
(0);
try
BitBlt(ScreenBmp.Canvas.Handle,0,0,Screen.Width,Screen.Height,dc,0,0,Flag);
finally
ReleaseDC(0,dc);
//根据标记判断是否画上光标
DrawCursorToBmp(ScreenBmp);
=TempPath+IntToStr(PicIndex)+'
.bmp'
ScreenBmp.SaveToFile(BmpFileName);
Inc(PicIndex);
except
onEIntOverflowdo
1.Button1Click(Sender:
timer
1.Enabled:
=True;
2.取保存的bmp图片生成avi并添加声音.
usesVFW;
AviFileName:
//AVI文件存储路径Tempbmp:
//生成AVI前读出的BMPfunctionGetBitmapData(bmp:
TBitmap):
TImageData;
bmp.PixelFormat:
Result.Width:
=bmp.Width;
Result.Height:
=bmp.Height;
Result.Stride:
=Result.Widthshl2;
Result.Scan0:
=bmp.ScanLine[Result.Height-1];
Result.PixelFormat:
=-1;
//Windowsbitmapformatflag
Result.Reserved:
procedureCreateAVI;
hr:
Strhdr:
TAVIStreamInfo;
//AVI流信息
Wavehdr:
TWaveFormatEx;
Opts:
TAVICOMPRESSOPTIONS;
//压缩选项
POpts:
PAVICOMPRESSOPTIONS;
//压缩选项指针
Bi:
BITMAPINFOHEADER;
//BMP头信息
B:
Boolean;
P:
Pointer;
i:
bmpData:
nRet:
ifFileExists(AviFileName)then
DeleteFile(AviFileName);
AVIFileInit;
=AVIFileOpen(PFile,PChar(AviFileName),OF_CREATEorOF_WRITE,nil);
if(hr<
>
0)then
//设置AVI流信息
ZeroMemory(@Strhdr,SizeOf(TAVIStreamInfo));
strhdr.fccType:
=streamTypeVIDEO;
strhdr.fccHandler:
=mmioFOURCC('
D'
'
I'
V'
X'
);
strhdr.dwFlags:
strhdr.dwCaps:
strhdr.wPriority:
strhdr.wLanguage:
strhdr.dwScale:
=1;
strhdr.dwRate:
=5;
//pfs
strhdr.dwStart:
strhdr.dwLength:
strhdr.dwInitialFrames:
strhdr.dwSuggestedBufferSize:
=((Screen.Width*3+3)and$FFFC)*screen.Height;
//Screen.Height*screen.Width*3;
strhdr.dwQuality:
strhdr.dwSampleSize:
strhdr.rcFrame:
=Rect(0,0,Screen.Width,Screen.Height);
strhdr.dwEditCount:
strhdr.dwFormatChangeCount:
strhdr.szName[0]:
=#0;
strhdr.szName[1]:
//设置WAV流信息
ZeroMemory(@Wavehdr,SizeOf(TWaveFormatEx));
Wavehdr.cbSize:
Wavehdr.nChannels:
Wavehdr.wFormatTag:
Wavehdr.wBitsPerSample:
=16;
Wavehdr.nSamplesPerSec:
=8000;
Wavehdr.nBlockAlign:
=Wavehdr.wBitsPerSample*Wavehdr.nChannelsdiv8;
Wavehdr.nAvgBytesPerSec:
=Wavehdr.nBlockAlign*
Wavehdr.nSamplesPerSec;
ZeroMemory(@opts,SizeOf(TAVICOMPRESSOPTIONS));
//设置压缩信息
//Indeo?
Video
5.10
opts.fccType:
//vids
opts.fccHandler:
=9;
opts.dwKeyFrameEvery:
opts.dwQuality:
=8500;
opts.dwBytesPerSecond:
opts.dwFlags:
=8;
opts.lpFormat:
=nil;
opts.cbFormat:
opts.cbParms:
=48;
opts.dwInterleaveEvery:
//设置BMP头信息
ZeroMemory(@bi,SizeOf(BITMAPINFOHEADER));
bi.biSize:
=SizeOf(bi);
bi.biWidth:
bi.biHeight:
bi.biPlanes:
bi.biBitCount:
=24;
bi.biCompression:
bi.biSizeImage:
=((Screen.Width*3+3)and$FFFC)*screen.Height;
//(((bih.biWidth*3)+3)&
0xFFFC)*bih.biHeight//Screen.Height*screen.Width*3;
//_stride*_height;
bi.biXPelsPerMeter:
bi.biYPelsPerMeter:
bi.biClrUsed:
bi.biClrImportant:
hr:
=AVIFileCreateStream(PFile,PSrcStream,@strhdr);
=AVIMakeCompressedStream(PCompStream,PSrcStream,@opts,nil);
Abort;
=AVIStreamSetFormat(PCompStream,20,@bi,40);
Tempbmp:
Tempbmp.LoadFromFile(bmpFile);
bmpData:
=GetBitmapData(Tempbmp);
=AVIStreamWrite(PCompStream,
FrameCount,//存在第几帧
1,
bmpData.Scan0,
((Screen.Width*3+3)and$FFFC)*screen.Height,
0,
nil,
nil);
//添加声音
AddAVISound;
procedureAddAVISound;
wfx:
TWAVEFORMATEX;
buf:
arrayofchar;
wav:
PWavChunk;
hf:
HWND;
size:
DWORD;
numbytes,numsamps:
ZeroMemory(@wfx,sizeof(TWAVEFORMATEX));
hf:
=CreateFile(PChar(WavFileName),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,0,0);
if(hf=0)then
size:
=GetFileSize(hf,nil);
SetLength(buf,size);
ReadFile(hf,buf[0],size,size,nil);
CloseHandle(hf);
wav:
=PWavChunk(buf);
wfx.wFormatTag:
=wav.fmt.wFormatTag;
wfx.cbSize:
wfx.nAvgBytesPerSec:
=wav.fmt.dwAvgBytesPerSec;
wfx.nBlockAlign:
=wav.fmt.wBlockAlign;
wfx.nChannels:
=wav.fmt.wChannels;
wfx.nSamplesPerSec:
=wav.fmt.dwSamplesPerSec;
wfx.wBitsPerSample:
=wav.fmt.wBitsPerSample;
Strhdr.fccType:
=streamtypeAUDIO;
Strhdr.dwScale:
=wfx.nBlockAlign;
Strhdr.dwRate:
=wfx.nSamplesPerSec*wfx.nBlockAlign;
Strhdr.dwSampleSize:
Strhdr.dwQuality:
=DWORD(-1);
=AVIFileCreateStream(PFile,PWavStream,@Strhdr);
if(buf<
nil)then
buf:
=AVIStreamSetFormat(PWavStream,0,@wfx,SizeOf(TWAVEFORMATEX));
//nowwecanwritethedata
numbytes:
=wav.dat.size;
ifwfx.wBitsPerSample<
0then
numsamps:
=numbytes*8divwfx.wBitsPerSample
else
=AVIStreamWrite(PWavStream,0,numsamps,wav,numbytes,0,nil,nil);
WavAddCompleted: