最近刚学的delphi,对里面的组件可谓又爱又恨.
下面是自己弄的一个BMP转AVI的小程序,以前记得是可以的,后来重装了系统,今天翻出来却怎么也不行了,郁闷:(
unit BmpToAvi;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DynamicSkinForm, StdCtrls, Spin, SkinCtrls, SkinBoxCtrls,
  ExtCtrls;type
  TForm1 = class(TForm)
    Image1: TImage;
    Label1: TspSkinStdLabel;
    Panel1: TspSkinPanel;
    Label2: TspSkinStdLabel;
    ListBox1: TspSkinListBox;
    addButton: TspSkinButton;
    DllButton: TspSkinButton;
    OkButton: TspSkinButton;
    CloseButton: TspSkinButton;
    SpinEdit1: TSpinEdit;
    DSF: TspDynamicSkinForm;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure addButtonClick(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
    procedure CloseButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure Log(Ph:String);
    Procedure CreerAvi;
  end;var
  Form1: TForm1;
  Fichier:String;implementation{$R *.dfm}Procedure Err(Ph:String);
Begin
 Beep;
 ShowMessage(Ph);
end;Procedure TForm1.Log(Ph:String);
Begin
 ListBox1.Items.Add(Ph);
End;Procedure TForm1.CreerAvi;
Var
 Reponse : Integer;
 C,C1:LongInt;
 Cp:LongWord;
 PFile1: PAVIFile;
 NewAvi: PAVIStream;
 AviInfo: PAviStreamInfo;
 Image:Pointer;
 InfoSize   : Dword ;
 ImageSize  : Dword ;
 BitmapInfo:PBitmapInfo;
 Procedure Sortie;
 Begin
  FreeMem(BitMapInfo);
  FreeMem(Image);
  Freemem(AviInfo);
 End;
Begin
try
 if SaveDialog1.Execute then
 begin
 AVIFileInit; // Ouvre le fichier a traiter New
 Reponse := AVIFileOpen(Pfile1,PChar(SaveDialog1.FileName),OF_WRITE or OF_CREATE,nil); if Reponse <> 0 then
  begin
   Sortie;
   Err('Erreur d''ouverture fichier ...');
   AVIFileExit;
   exit;
  end; // Declaration des parametres Avi GetDIBSizes(Image1.Picture.Bitmap.Handle, InfoSize, ImageSize);
 Image1.Refresh;
 GetMem(BitMapInfo,InfoSize);
 ZeroMemory(BitMapInfo,InfoSize);
 GetMem(Image,ImageSize);
 ZeroMemory(Image,ImageSize); GetDIB(Image1.Picture.Bitmap.Handle,Image1.Picture.Bitmap.Palette,BitmapInfo^,Image^); Getmem(AviInfo,Sizeof(TAviStreamInfo));
 ZeroMemory(AviInfo,Sizeof(TAviStreamInfo)); AviInfo^.fccType:=StreamTypeVideo;
 AviInfo^.fccHandler:=Bi_RGB;
 AviInfo^.dwScale:= 1;
 AviInfo^.dwRate:=SpinEdit1.Value ;
 AviInfo^.rcFrame:=Rect(0,0,BitMapInfo^.BmiHeader.BiWidth,BitMapInfo^.BmiHeader.BiHeight);
 AviInfo^.dwSuggestedBufferSize:=ImageSize; BitMapInfo^.BmiHeader.BiCompression:=Bi_RGB; // Creer le stream video du nouveau fichier AVI New
 Reponse := AVIFileCreateStream(PFile1,NewAvi,AviInfo^);
 if Reponse <> AVIERR_OK then
  begin
   Sortie;
   Err('Erreur de creation du Stream ...');
   AVIFileRelease(Pfile1);
   AVIFileExit;
   exit;
  end; Reponse :=AVIStreamSetFormat(NewAvi,0,BitmapInfo,InfoSize);
 if Reponse <> AVIERR_OK then
  begin
   Sortie;
   Err('Erreur de formatage du Stream Video ...');
   AVIStreamRelease(NewAvi);
   AVIFileRelease(Pfile1);
   AVIFileExit;
   exit;
  end; For Cp:=0 to ListBox1.Items.count-1 do
 Begin  // Ecrit la Frame dans le fichier
  // ------------------------------
  //Label5.Caption:='Image : '+IntToStr(Cp)+' / '+IntToStr(ListBox1.Items.count);
  //Label5.Refresh;  Image1.Picture.LoadFromFile(ListBox1.Items[Cp]);
  Image1.Refresh;
  GetDIB(Image1.Picture.Bitmap.Handle,Image1.Picture.Bitmap.Palette,BitmapInfo^,Image^);
  Image1.Refresh;  // Ecrit le stream video
  Reponse:=AVIStreamWrite(NewAvi,Cp,1,Image,ImageSize,AVIIF_KEYFRAME,C,C1);
  if Reponse <> AVIERR_OK then
  begin
   Sortie;
   AVIStreamRelease(NewAvi);
   AVIFileRelease(Pfile1);
   AVIFileExit;
   Err('Erreur Stream Video Write ...');
   Exit;
  end; End; Sortie; AVIStreamRelease(NewAvi);
 AVIFileRelease(Pfile1);
 AVIFileExit;
 end;
except
end;
End;procedure TForm1.addButtonClick(Sender: TObject);
var
i:integer;
begin
 OpenDialog1.Filter := 'BMP位图 (*.bmp)|*.bmp';
 OpenDialog1.FileName:='*.bmp';
 OpenDialog1.FilterIndex := 2;
 If OpenDialog1.Execute then
  Begin
   for i:=0 to OpenDialog1.Files.Count-1 do
   begin
     Fichier:=OpenDialog1.Files.Strings[i];
     If Pos('*.bmp',Fichier)=0 then
       Begin
         Image1.Picture.LoadfromFile(Fichier);
         ListBox1.Items.Add(Fichier);
       End;
   end;
  End;
end;procedure TForm1.OkButtonClick(Sender: TObject);
begin
//CreerAvi;
end;procedure TForm1.CloseButtonClick(Sender: TObject);
begin
Close;
end;
end.
[错误] BmpToAvi.pas(60): Undeclared identifier: 'PAVIFile'
[错误] BmpToAvi.pas(61): Undeclared identifier: 'PAVIStream'
[错误] BmpToAvi.pas(62): Undeclared identifier: 'PAviStreamInfo'
[错误] BmpToAvi.pas(71): Incompatible types
[错误] BmpToAvi.pas(77): Undeclared identifier: 'AVIFileInit'
[错误] BmpToAvi.pas(80): Undeclared identifier: 'AVIFileOpen'
[错误] BmpToAvi.pas(86): Undeclared identifier: 'AVIFileExit'
[错误] BmpToAvi.pas(101): Incompatible types
[错误] BmpToAvi.pas(104): Pointer type required
[错误] BmpToAvi.pas(105): Pointer type required
[错误] BmpToAvi.pas(106): Pointer type required
[错误] BmpToAvi.pas(107): Pointer type required
[错误] BmpToAvi.pas(108): Pointer type required
[错误] BmpToAvi.pas(109): Pointer type required
[错误] BmpToAvi.pas(114): Undeclared identifier: 'AVIFileCreateStream'
[错误] BmpToAvi.pas(114): Pointer type required
[错误] BmpToAvi.pas(115): Undeclared identifier: 'AVIERR_OK'
[错误] BmpToAvi.pas(119): Undeclared identifier: 'AVIFileRelease'
[错误] BmpToAvi.pas(124): Undeclared identifier: 'AVIStreamSetFormat'
[错误] BmpToAvi.pas(129): Undeclared identifier: 'AVIStreamRelease'
[错误] BmpToAvi.pas(149): Undeclared identifier: 'AVIStreamWrite'
[错误] BmpToAvi.pas(149): Undeclared identifier: 'AVIIF_KEYFRAME'
[致命错误] BmpToAvi1.dpr(5): Could not compile used unit 'BmpToAvi.pas'

解决方案 »

  1.   

    若是需要装什么组件的话,大哥大姐们给我传下,谢谢了.
    [email protected]
      

  2.   

    uses
    VFW;相关的单元文件:http://www.koders.com/delphi/fidF901E0AEC29ECBF67266B86173AA1121B5BB4430.aspx
      

  3.   

     谢谢unsigned ,我开始也装了VFW.pas,应该就是没加
    uses 
    VFW; 后来重新装了下VFW.pas,加上VFW就可以了,另外代码上还有点小问题,我把最后的可行的贴出来
    unit BmpToAvi;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DynamicSkinForm, StdCtrls, Spin, SkinCtrls, SkinBoxCtrls,
      ExtCtrls,VFW;type
      TForm1 = class(TForm)
        Image1: TImage;
        Label1: TspSkinStdLabel;
        Panel1: TspSkinPanel;
        Label2: TspSkinStdLabel;
        ListBox1: TspSkinListBox;
        addButton: TspSkinButton;
        DllButton: TspSkinButton;
        OkButton: TspSkinButton;
        CloseButton: TspSkinButton;
        SpinEdit1: TSpinEdit;
        DSF: TspDynamicSkinForm;
        OpenDialog1: TOpenDialog;
        SaveDialog1: TSaveDialog;
        procedure addButtonClick(Sender: TObject);
        procedure OkButtonClick(Sender: TObject);
        procedure CloseButtonClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        Procedure Log(Ph:String);
        Procedure CreerAvi;
      end;var
      Form1: TForm1;
      Fichier:String;implementation{$R *.dfm}Procedure Err(Ph:String);
    Begin
     Beep;
     ShowMessage(Ph);
    end;Procedure TForm1.Log(Ph:String);
    Begin
     ListBox1.Items.Add(Ph);
    End;Procedure TForm1.CreerAvi;
    Var
     Reponse : Integer;
     C,C1:LongInt;
     Cp:LongWord;
     PFile1: PAVIFile;
     NewAvi: PAVIStream;
     AviInfo: PAviStreamInfo;
     Image:Pointer;
     InfoSize   : Dword ;
     ImageSize  : Dword ;
     BitmapInfo:PBitmapInfo;
     Procedure Sortie;
     Begin
      FreeMem(BitMapInfo);
      FreeMem(Image);
      Freemem(AviInfo);
     End;
    Begin
    try
     if SaveDialog1.Execute then
     begin
     AVIFileInit; // Ouvre le fichier a traiter New
     Reponse := AVIFileOpen(Pfile1,PChar(SaveDialog1.FileName),OF_WRITE or OF_CREATE,nil); if Reponse <> 0 then
      begin
       Sortie;
       Err('Erreur d''ouverture fichier ...');
       AVIFileExit;
       exit;
      end; // Declaration des parametres Avi GetDIBSizes(Image1.Picture.Bitmap.Handle, InfoSize, ImageSize);
     Image1.Refresh;
     GetMem(BitMapInfo,InfoSize);
     ZeroMemory(BitMapInfo,InfoSize);
     GetMem(Image,ImageSize);
     ZeroMemory(Image,ImageSize); GetDIB(Image1.Picture.Bitmap.Handle,Image1.Picture.Bitmap.Palette,BitmapInfo^,Image^); Getmem(AviInfo,Sizeof(TAviStreamInfo));
     ZeroMemory(AviInfo,Sizeof(TAviStreamInfo)); AviInfo^.fccType:=StreamTypeVideo;
     AviInfo^.fccHandler:=Bi_RGB;
     AviInfo^.dwScale:= 1;
     AviInfo^.dwRate:=SpinEdit1.Value ;
     AviInfo^.rcFrame:=Rect(0,0,BitMapInfo^.BmiHeader.BiWidth,BitMapInfo^.BmiHeader.BiHeight);
     AviInfo^.dwSuggestedBufferSize:=ImageSize; BitMapInfo^.BmiHeader.BiCompression:=Bi_RGB; // Creer le stream video du nouveau fichier AVI New
     Reponse := AVIFileCreateStream(PFile1,NewAvi,AviInfo);
     if Reponse <> AVIERR_OK then
      begin
       Sortie;
       Err('Erreur de creation du Stream ...');
       AVIFileRelease(Pfile1);
       AVIFileExit;
       exit;
      end; Reponse :=AVIStreamSetFormat(NewAvi,0,BitmapInfo,InfoSize);
     if Reponse <> AVIERR_OK then
      begin
       Sortie;
       Err('Erreur de formatage du Stream Video ...');
       AVIStreamRelease(NewAvi);
       AVIFileRelease(Pfile1);
       AVIFileExit;
       exit;
      end; For Cp:=0 to ListBox1.Items.count-1 do
     Begin  // Ecrit la Frame dans le fichier
      // ------------------------------
      //Label5.Caption:='Image : '+IntToStr(Cp)+' / '+IntToStr(ListBox1.Items.count);
      //Label5.Refresh;  Image1.Picture.LoadFromFile(ListBox1.Items[Cp]);
      Image1.Refresh;
      GetDIB(Image1.Picture.Bitmap.Handle,Image1.Picture.Bitmap.Palette,BitmapInfo^,Image^);
      Image1.Refresh;  // Ecrit le stream video
      ///////////////////下面@C,@C1为PDWORD
      Reponse:=AVIStreamWrite(NewAvi,Cp,1,Image,ImageSize,AVIIF_KEYFRAME,@C,@C1);
      if Reponse <> AVIERR_OK then
      begin
       Sortie;
       AVIStreamRelease(NewAvi);
       AVIFileRelease(Pfile1);
       AVIFileExit;
       Err('Erreur Stream Video Write ...');
       Exit;
      end; End; Sortie; AVIStreamRelease(NewAvi);
     AVIFileRelease(Pfile1);
     AVIFileExit;
     end;
    except
    end;
    End;procedure TForm1.addButtonClick(Sender: TObject);
    var
    i:integer;
    begin
     OpenDialog1.Filter := 'BMP位图 (*.bmp)|*.bmp';
     OpenDialog1.FileName:='*.bmp';
     OpenDialog1.FilterIndex := 2;
     If OpenDialog1.Execute then
      Begin
       for i:=0 to OpenDialog1.Files.Count-1 do
       begin
         Fichier:=OpenDialog1.Files.Strings[i];
         If Pos('*.bmp',Fichier)=0 then
           Begin
             Image1.Picture.LoadfromFile(Fichier);
             ListBox1.Items.Add(Fichier);
           End;
       end;
      End;
    end;procedure TForm1.OkButtonClick(Sender: TObject);
    begin
    CreerAvi;
    end;procedure TForm1.CloseButtonClick(Sender: TObject);
    begin
    Close;
    end;