怎么提取AVI文件的第一帧图象 通商 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function GetAviFrame(AviFilename : String; Index: Integer; var bmp: TBitmap):boolean;说明:avifilename: avi文件名index: 要取的帧号bmp: 存放返回图象, 如果为nil则自动建立一个bitmap. 如果存在则按bmp定义的大小存放stretch后的图象.返回值: true 成功, false 失败现在的问题是编译没有问题,但是我用一个Image控件显示得到的BMP图片时,却发现根本得不到第一帧的图片,请DELPHI高手帮忙!!!,多谢!!!函数代码如下:unit Unit_GetAviFrame;interfaceuses windows, graphics;const streamtypeAUDIO : longint = $73647561; streamtypeVIDEO : longint = $73646976;type TAVIStream = record fccType : longint; fccHandler : longint; dwFlags : longint; dwCaps : longint; wPriority : word; wLanguage : word; dwScale : longint; dwRate : longint; dwStart : longint; dwLength : longint; dwInitialFrames : longint; dwSuggestedBufferSize : longint; dwQuality : longint; dwSampleSize : longint; rcFrame : TRect; dwEditCount : longint; dwFormatChangeCount : longint; Name : array [0..64] of char; end; PAVIStream = ^TAVIStream; PAVIFile = pointer; TAVIFileInfo = record dwMaxBytesPerSec : longint; dwFlags : longint; dwCaps : longint; dwStreams : longint; dwSuggestedBufferSize : longint; dwWidth : longint; dwHeight : longint; dwScale : longint; dwRate : longint; dwLength : longint; dwEditCount : longint; szFileType : array[0..63] of char; end; PAVIFileInfo = ^TAVIFileInfo; TAVIStreamInfo = record fccType : longint; fccHandler : longint; dwFlags : longint; dwCaps : longint; wPriority : word; wLanguage : word; dwScale : longint; dwRate : longint; dwStart : longint; dwLength : longint; dwInitialFrames : longint; dwSuggestedBufferSize : longint; dwQuality : longint; dwSampleSize : longint; rcFrame : TRect; dwEditCount : longint; dwFormatChangeCount : longint; szName : array[0..63] of char; end; PAVIStreamInfo = ^TAVIStreamInfo;function AVIFileOpen(avifile : pointer; filename : pchar; mode : integer; CLSID : pointer) : integer; stdcall; external 'avifil32.dll' index 16;function AVIFileRelease(avifile : pointer) : longint; stdcall; external 'avifil32.dll' index 20;function AVIFileGetStream(avifile : pointer; avistream : PAVIStream; streamtype : longint; lParam : longint) : integer;stdcall;external 'avifil32.dll' index 11;function AVIStreamGetFrameOpen(avistream : PAVIStream; bitmapwanted : pointer) : pointer;stdcall; external 'avifil32.dll' index 42;procedure AVIStreamGetFrameClose(pget : pointer); stdcall; external 'avifil32.dll' index 41;function AVIStreamGetFrame(getframe : pointer; position : longint) : pointer; stdcall;external 'avifil32.dll' index 40;procedure AVIStreamRelease(avistream : PAVIStream); stdcall; external 'avifil32.dll' index 53;function AVIStreamInfo(pstream : PAVIStream; psi : PAVISTREAMINFO; lsize : longint) :integer; stdcall; external 'avifil32.dll' index 44;function GetAviFrame(AviFilename : String; Index: Integer; var bmp: TBitmap):boolean;implementationfunction GetAviFrame(AviFilename : String; Index: Integer; var bmp: TBitmap):boolean;var FAviFile : Pointer; FVideoStream : Pointer; FGetFrame : Pointer; info : TAVIStreamInfo; FFrameWidth, FFrameHeight : Integer; FStartFrame, FStopFrame : Integer; image : pointer; imagestart : Integer;begin result := false; if (AVIFileOpen(@favifile, pchar(AviFileName), 0, nil) <> 0) then exit; if (AVIFileGetStream(favifile, @fvideostream, streamtypeVIDEO, 0) <> 0) then begin AVIFileRelease(favifile); exit; end; AVIStreamInfo(fvideostream, @info, sizeof(info)); with info do begin fFrameWidth := rcframe.right - rcframe.left; fFrameHeight := rcframe.bottom - rcframe.top; fStartFrame := dwStart; fStopFrame := dwLength - 1; end; if (index <fstartframe) or (index > fstopframe) then begin AVIStreamRelease(fvideostream); AVIFileRelease(favifile); exit; end; fgetframe := AVIStreamGetFrameOpen(fvideostream, nil); if (fgetframe = nil) then begin AVIStreamRelease(fvideostream); AVIFileRelease(favifile); exit; end; image := AVIStreamGetFrame(fGetFrame, Index); if assigned(image) then begin if not assigned(bmp) then begin bmp := tbitmap.create; bmp.width := fframewidth; bmp.height := fframeheight; end else if bmp.empty then begin bmp.width := fframewidth; bmp.height := fframeheight; end; imagestart := TBitmapInfoHeader(image^).biSize + TBitmapInfoHeader(image^).biClrUsed * 4; StretchDIBits(bmp.canvas.handle, 0, 0, bmp.width, bmp.height, 0, 0, fframewidth, fframeheight, pchar(image) + imagestart, TBitmapInfo(image^), 0, SRCCOPY); result := true; end; AVIStreamGetFrameClose(fgetframe); AVIStreamRelease(fvideostream); AVIFileRelease(favifile);end;end.//显示图片的代码如下(在空白窗体上添加一个Image控件和Button控件)procedure TForm1.Button1Click(Sender: TObject);var bmp : Tbitmap;begin bmp := Tbitmap.Create; if (Unit_GetAviFrame.GetAviFrame('2.avi',1000,bmp) = True) then begin image1.Picture.Bitmap.Assign(bmp); Image1.Refresh; showmessage('ok'); end; bmp.Free;end; vc6.0怎么调用vc.net类库生成的dll? 使用DataGrid控件的问题,ADO连接ACCESS数据库(小妹在线等答案。急啊) 怎样打开文件夹 如何给文字添加链接? 新手碰到一难题,大家来帮帮忙! 关于做语音网关,有没有人知道这样一块内容,有哪些东西要准备! 谁有在线自动更新软件的控件?最好能提供原代码!谢谢! 初学VC++,打开一个例子,编译出错,哪位位能帮我看看??? 求助 :::::关于线程同步--- 请问正在上海工作的朋友,上海有哪些感觉比较好的软件公司??????????????? 关于隐藏文件菜单的问题 如何让ClistCtrl中的check box支持三态
boolean;
说明:
avifilename: avi文件名
index: 要取的帧号
bmp: 存放返回图象, 如果为nil则自动建立一个bitmap. 如果存在则按bmp定义的大小存放stretch后的图象.
返回值: true 成功, false 失败
现在的问题是编译没有问题,但是我用一个Image控件显示得到的BMP图片时,却发现根本得不到第一帧的
图片,请DELPHI高手帮忙!!!,多谢!!!
函数代码如下:
unit Unit_GetAviFrame;
interface
uses windows, graphics;
const
streamtypeAUDIO : longint = $73647561;
streamtypeVIDEO : longint = $73646976;
type
TAVIStream = record
fccType : longint;
fccHandler : longint;
dwFlags : longint;
dwCaps : longint;
wPriority : word;
wLanguage : word;
dwScale : longint;
dwRate : longint;
dwStart : longint;
dwLength : longint;
dwInitialFrames : longint;
dwSuggestedBufferSize : longint;
dwQuality : longint;
dwSampleSize : longint;
rcFrame : TRect;
dwEditCount : longint;
dwFormatChangeCount : longint;
Name : array [0..64] of char;
end;
PAVIStream = ^TAVIStream;
PAVIFile = pointer;
TAVIFileInfo = record
dwMaxBytesPerSec : longint;
dwFlags : longint;
dwCaps : longint;
dwStreams : longint;
dwSuggestedBufferSize : longint;
dwWidth : longint;
dwHeight : longint;
dwScale : longint;
dwRate : longint;
dwLength : longint;
dwEditCount : longint;
szFileType : array[0..63] of char;
end;
PAVIFileInfo = ^TAVIFileInfo;
TAVIStreamInfo = record
fccType : longint;
fccHandler : longint;
dwFlags : longint;
dwCaps : longint;
wPriority : word;
wLanguage : word;
dwScale : longint;
dwRate : longint;
dwStart : longint;
dwLength : longint;
dwInitialFrames : longint;
dwSuggestedBufferSize : longint;
dwQuality : longint;
dwSampleSize : longint;
rcFrame : TRect;
dwEditCount : longint;
dwFormatChangeCount : longint;
szName : array[0..63] of char;
end;
PAVIStreamInfo = ^TAVIStreamInfo;
function AVIFileOpen(avifile : pointer; filename : pchar; mode : integer;
CLSID : pointer) : integer; stdcall; external 'avifil32.dll
' index 16;
function AVIFileRelease(avifile : pointer) : longint; stdcall; external 'avif
il32.dll' index 20;
function AVIFileGetStream(avifile : pointer; avistream : PAVIStream;
streamtype : longint; lParam : longint) : integer;
stdcall;
external 'avifil32.dll' index 11;
function AVIStreamGetFrameOpen(avistream : PAVIStream; bitmapwanted : pointer
) : pointer;
stdcall; external 'avifil32.dll' index 42;
procedure AVIStreamGetFrameClose(pget : pointer); stdcall; external 'avifil32.
dll' index 41;
function AVIStreamGetFrame(getframe : pointer; position : longint) : pointer;
stdcall;
external 'avifil32.dll' index 40;
procedure AVIStreamRelease(avistream : PAVIStream); stdcall; external 'avifil3
2.dll' index 53;
function AVIStreamInfo(pstream : PAVIStream; psi : PAVISTREAMINFO; lsize : lo
ngint) :
integer; stdcall; external 'avifil32.dll' index 44;
function GetAviFrame(AviFilename : String; Index: Integer; var bmp: TBitmap):
boolean;
implementation
function GetAviFrame(AviFilename : String; Index: Integer; var bmp: TBitmap):
boolean;
var
FAviFile : Pointer;
FVideoStream : Pointer;
FGetFrame : Pointer;
info : TAVIStreamInfo;
FFrameWidth, FFrameHeight : Integer;
FStartFrame, FStopFrame : Integer;
image : pointer;
imagestart : Integer;
begin
result := false;
if (AVIFileOpen(@favifile, pchar(AviFileName), 0, nil) <> 0) then
exit;
if (AVIFileGetStream(favifile, @fvideostream, streamtypeVIDEO, 0) <> 0) then
begin
AVIFileRelease(favifile);
exit;
end;
AVIStreamInfo(fvideostream, @info, sizeof(info));
with info do
begin
fFrameWidth := rcframe.right - rcframe.left;
fFrameHeight := rcframe.bottom - rcframe.top;
fStartFrame := dwStart;
fStopFrame := dwLength - 1;
end;
if (index <fstartframe) or (index > fstopframe) then
begin
AVIStreamRelease(fvideostream);
AVIFileRelease(favifile);
exit;
end;
fgetframe := AVIStreamGetFrameOpen(fvideostream, nil);
if (fgetframe = nil) then
begin
AVIStreamRelease(fvideostream);
AVIFileRelease(favifile);
exit;
end;
image := AVIStreamGetFrame(fGetFrame, Index);
if assigned(image) then
begin
if not assigned(bmp) then
begin
bmp := tbitmap.create;
bmp.width := fframewidth;
bmp.height := fframeheight;
end
else if bmp.empty then
begin
bmp.width := fframewidth;
bmp.height := fframeheight;
end;
imagestart := TBitmapInfoHeader(image^).biSize +
TBitmapInfoHeader(image^).biClrUsed * 4;
StretchDIBits(bmp.canvas.handle, 0, 0, bmp.width, bmp.height,
0, 0, fframewidth, fframeheight,
pchar(image) + imagestart,
TBitmapInfo(image^), 0, SRCCOPY);
result := true;
end;
AVIStreamGetFrameClose(fgetframe);
AVIStreamRelease(fvideostream);
AVIFileRelease(favifile);
end;
end.//显示图片的代码如下(在空白窗体上添加一个Image控件和Button控件)
procedure TForm1.Button1Click(Sender: TObject);
var
bmp : Tbitmap;
begin
bmp := Tbitmap.Create;
if (Unit_GetAviFrame.GetAviFrame('2.avi',1000,bmp) = True) then
begin
image1.Picture.Bitmap.Assign(bmp);
Image1.Refresh;
showmessage('ok');
end;
bmp.Free;
end;