I found a way to write avi from BMP files:
http://www.delphi3000.com/articles/article_2770.asp?SK=
I want to write avi from array or TList of TBitmaps?
views:
186answers:
1The key portion of the code you linked to is below, where IList
is a TStrings
with the names of all the files to include in the animation.
for i := 0 to IList.Count - 1 do begin
AssignFile(BFile, IList[i]);
Reset(BFile, 1);
Seek(BFile, m_bfh.bfOffBits);
BlockRead(BFile, m_MemBits[0], m_Bih.biSizeImage);
Seek(BFile, SizeOf(m_Bfh));
BlockRead(BFile, m_MemBitMapInfo[0], length(m_MemBitMapInfo));
CloseFile(BFile);
if AVIStreamWrite(psCompressed, i, 1, @m_MemBits[0],
m_Bih.biSizeImage, AVIIF_KEYFRAME, 0, 0) <> 0 then begin
ShowMessage('Error during Write AVI File');
break;
end;
end;
It reads portions of the file from disk and writes them to the AVI stream. The important part is that it reads from the files. The in-memory representation of a TBitmap
doesn't necessarily match with the representation of a file. However, it's easy to adapt the given code to temporarily store the bitmaps in a memory stream; the stream will match what the layout of the file would be. Suppose IList
is now an array of TBitmap
, as you suggested. Then we could use this:
var
ms: TMemoryStream;
ms := TMemoryStream.Create;
try
for i := 0 to Length(IList) - 1 do begin
IList[i].SaveToStream(ms);
ms.Position := m_bfh.bfOffBits;
ms.ReadBuffer(m_MemBits[0], m_Bih.biSizeImage);
ms.Position := SizeOf(m_Bfh);
ms.ReadBuffer(m_MemBitMapInfo[0], Length(m_MemBitMapInfo));
ms.Clear;
if AVIStreamWrite(psCompressed, i, 1, @m_MemBits[0],
m_Bih.biSizeImage, AVIIF_KEYFRAME, 0, 0) <> 0 then begin
ShowMessage('Error during Write AVI File');
break;
end;
end;
finally
ms.Free;
end;
There's code earlier in your cited example that reads the first file in the list to populate the various records and size the arrays used here, but you should be able to make the same changes there as I have done to the code shown here.