How to write avi file from TBitmaps sequence?
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 from TBitmaps?
source to share
Below is the key piece of code that you linked to, where IList
is this TStrings
with the names of all the files that should be included 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 chunks of a file from disk and writes them to an AVI stream. The important part is that it reads from files. The TBitmap
memory representation does not necessarily match the file representation. However, it is easy to adapt this code to temporarily store bitmaps in a memory stream; the stream will match the layout of the file. Suppose IList
now is an array 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;
In the example above, the code that reads the first file in the list populates the various entries and sizes of the arrays used here, but you should be able to make the same changes there as I did with the code here.
source to share