我写的一个一个过程运行是出现“Acess violation at adress 74800BEF in module "msvcrt.dll",
  Read of adress 68C6F387”,这是出了什么问题

解决方案 »

  1.   

    procedure TForm1.BmpToAvi(FileDir: string;Filedest:string);
    //procedure BmpToAvi(FileDir: string;Filedest:string);
    var
      Sr:TSearchRec;
      FileAtr:integer;
      str:string;
      bFind:Integer;
      nFrames:integer;
      hr:HRESULT;
      tmp_buf:array of byte;  fp:hFile;
      StreamInfo:TAVISTREAMINFO;
      pFile:IAVIFILE;
      ps:IAVISTREAM;
      bmpFileHeader:BITMAPFILEHEADER;
      bmpInfoHeader:BITMAPINFOHEADER;
    begin
      nFrames:=0;
      str:=FileDir+'*.*';
      AVIFileInit();
      bFind:=FindFirst(str,faAnyFile,sr);
            while (bFind=0) do
              begin
                bFind:=FindNext(Sr);
                if (Sr.Name[1]<>'.') and (sr.Attr<>faDirectory) then
                    begin                  str:=ExpandFileName(Sr.Name);
                      //fp:=_lopen(pChar(str),OF_READWRITE);
                      fp:=FileOpen(str,fmOpenWrite);                  //_llseek(fp,0,FILE_BEGIN);
                      FileSeek(fp,0,0);
                      //_lread(fp,@bmpFileHeader,sizeof(bmpFileHeader));
                      FileRead(fp,bmpFileHeader,sizeof(bmpFileHeader));
                      //_lread(fp,@bmpInfoHeader,sizeof(BITMAPINFOHEADER));
                      FileRead(fp,bmpInfoHeader,sizeof(BITMAPINFOHEADER));//                  tmp_buf:= nil;                  if (nFrames=0) then
                         begin
                           AVIFileOpen(pFile,PChar(Filedest),OF_WRITE or OF_CREATE,nil);
                           FillMemory(@StreamInfo,sizeof(StreamInfo),0);
                           StreamInfo.fccType:=streamtypeVIDEO;
                           StreamInfo.fccHandler := 0;
                           StreamInfo.dwScale := 1;
                           StreamInfo.dwRate := 15; // 15 fps
                           StreamInfo.dwSuggestedBufferSize := bmpInfoHeader.biSizeImage ;
                           SetRect(StreamInfo.rcFrame, 0, 0, bmpInfoHeader.biWidth, bmpInfoHeader.biHeight);
                           hr := AVIFileCreateStream(pFile,ps,StreamInfo);
                         end;//                   getmem(tmp_buf,bmpInfoHeader.biWidth * bmpInfoHeader.biHeight * 3);                   //_lread(fp,tmp_buf,bmpInfoHeader.biWidth * bmpInfoHeader.biHeight * 3);
                       FileRead(fp,tmp_buf,bmpInfoHeader.biWidth * bmpInfoHeader.biHeight * 3);
                       hr := AVIStreamSetFormat(ps,nFrames,@bmpInfoHeader,sizeof(bmpInfoHeader));                   hr := AVIStreamWrite(ps, // stream
                                           nFrames , // time of this frame
                                           1, // number to write
                                           tmp_buf,
                                           bmpInfoHeader.biSizeImage , // size of this frame
                                           AVIIF_KEYFRAME, // flags....
                                           Nil,
                                           Nil);
                       label1.Caption:=inttostr(nFrames);
                       nFrames:=nFrames+1;
                       //_lclose(fp);
                       FileClose(fp);
    //                   freemem(tmp_buf);
                    end;
              end;  showmessage(inttostr(5));  if (ps<>nil) then
         begin
         AVIStreamClose(ps);  showmessage(inttostr(6));
         end;  if (pfile <> nil) then
         begin
         AVIFileRelease(pfile);  showmessage(inttostr(7));
         end;  AVIFileExit();  showmessage(inttostr(8));
    end;
    我写的是一个将一组BMP图片合成avi的过程,运行到hr := AVIStreamWrite(ps, // stream
                                           nFrames , // time of this frame
                                           1, // number to write
                                           tmp_buf,
                                           bmpInfoHeader.biSizeImage , // size of this   frame
                                           AVIIF_KEYFRAME, // flags....
                                           Nil,
                                           Nil);
    时就会出现上述错误。
    加上getmem(tmp_buf,bmpInfoHeader.biWidth * bmpInfoHeader.biHeight * 3);运行到这一句时会出现"out of memeory".
    开始用_lopen一类的API函数到是可以合成AVI,但是退出过程是报错,有时甚至死机。