Listing 11


//einen Frame (Einzelbild) aus einem AVIFile laden

unit Frames;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, MPlayer, MMSystem, VfW;

function GetAVIFrame(avifn: string; dc: HDC; TmpBmp : TBitmap; lPos: LONG) : Boolean;

implementation

function GetAVIFrame(avifn: string; dc: HDC; TmpBmp : TBitmap; lPos: LONG) : Boolean;
var
  retc       : Integer;
  pfile      : PAVIFile;
  gapavi   : PAVIStream;
  gapgf     : PGETFRAME;
  lpbi       : PBITMAPINFOHEADER;
  bits       : PChar;
  hBmp   : HBITMAP;

begin
  Result := FALSE;

  AVIFileInit;

  retc := AVIFileOpen(pfile, PChar(avifn), 0, nil);
  if retc <> 0 then
  begin
     AVIFileExit;
     Exit;
  end;

  retc := AVIFileGetStream(pfile, gapavi, 0, 0);
  if retc <> AVIERR_OK then
  begin
     AVIFileRelease(pfile);
     AVIFileExit;
     Exit;
  end;

  gapgf := AVIStreamGetFrameOpen(gapavi, nil);
  if gapgf = nil then
  begin
     AVIStreamRelease(gapavi);
     AVIFileRelease(pfile);
     AVIFileExit;
     Exit;
  end;

  // angegebenen Frame  lesen
  lpbi := AVIStreamGetFrame(gapgf, lPos);
  if lpbi = nil then
  begin
     AVIStreamGetFrameClose(gapgf);
     AVIStreamRelease(gapavi);
     AVIFileRelease(pfile);
     AVIFileExit;
     Exit;
  end;

  TmpBmp.Height := lpbi.biHeight;
  TmpBmp.Width  := lpbi.biWidth;

  bits := Pointer(Integer(lpbi) + sizeof(TBITMAPINFOHEADER));
  hBmp := CreateDIBitmap(dc, lpbi^, CBM_INIT, bits, PBITMAPINFO(lpbi)^, DIB_RGB_COLORS);
 
  TmpBmp.Handle := hBmp;

  Result := TRUE;

  AVIStreamGetFrameClose(gapgf);
  AVIStreamRelease(gapavi);
  AVIFileRelease(pfile);
  AVIFileExit;
end;

end.

Zurück zur Hauptseite