急!!将一组图象存入一个TStringList的问题?(100分)

  • 主题发起人 剑知心
  • 开始时间

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个将不定数量的连续bitmap 转换成一个视频的程序,需要将一组bitmap 存入一个
TStringlist对象。我的代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
Slist : TStringList;
Bmp : TBitmap;
I : Char
begin
Slist :=TStringList.Create;
Bmp :=TBitmap.Create;
for I:='1' to '5' do
begin
Bmp.LoadFromFile('e:/bmp/00' + i + '.bmp');
Slist.AddObject('bimap',TObject(Bmp));
end;
Image1.Picture.Bitmap :=TBitmap(slist.Objects[0]);
Image2.Picture.Bitmap := TBitmap(Slist.Objects[4]);
Slist.Free;
Bmp.Free;
end;
因为Tstringlist保存的是一个指向对象的指针,所以两个image显示的都是最后一张图片
如果改用动态数组 bmps : array of TBitmap;结果也是一样的,这个问题我该如何解决?
 
S

Sachow

Unregistered / Unconfirmed
GUEST, unregistred user!
问题不是出在如何读入图片上,而是出在如何播放图片上。说说你是怎么播放图片的?
 

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
我通过AviWriter组件将一组Bitmap : TList;写成一个AVI
 
L

LanFairy

Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段程序可以实现你的目的,你可以试一下,如果正确别忘了加分

procedure TForm1.Button1Click(Sender: TObject);
var
bmps : array of TfileStream;
bmp: TBitMap;
i: Integer;
begin
bmp := TBitMap.Create;
setlength(bmps, 5);
for i := 0 to 4 do
begin
bmps := TFileStream.Create('e:/bmp/00' + IntToStr(i) + '.bmp', fmOpenRead);
end;
bmp.LoadFromStream(bmps[0]);
Image1.Picture.Bitmap := bmp;
bmp.LoadFromStream(bmps[1]);
Image2.Picture.Bitmap := bmp;
end;
 

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
to LanFairy:
我可以把图片放入Tbitmap数组吗?
 

车金明

Unregistered / Unconfirmed
GUEST, unregistred user!
你的程序只需改动一行代码位置即可:如下
将Bmp :=TBitmap.Create;移到for循环的begin语句后就行了。每次生成一个新位图
对象实例。
 

车金明

Unregistered / Unconfirmed
GUEST, unregistred user!
你的程序只需改动一行代码位置即可:如下
将Bmp :=TBitmap.Create;移到for循环的begin语句后就行了。每次生成一个新位图
对象实例。
 

车金明

Unregistered / Unconfirmed
GUEST, unregistred user!
你的程序只需改动一行代码位置即可:如下
将Bmp :=TBitmap.Create;移到for循环的begin语句后就行了。每次生成一个新位图
对象实例。
 
S

sonie

Unregistered / Unconfirmed
GUEST, unregistred user!
1.我看你最好还是不要把图片存到TStringList.delphi里的帮助写得很明白:TStringList maintains a list of strings.
2.用车金明的方法是可以的
3.另最好是把
Image1.Picture.Bitmap :=TBitmap(slist.Objects[0]);
Image2.Picture.Bitmap := TBitmap(Slist.Objects[4])

Slist.Free;
改成
image1.picture.bitmap.assign(TBitmap(slist.objects[0]);
....
for i:=0 to 4 do
TBitmap(slist.objects[0]).free;
slist.free;
 
Y

yap

Unregistered / Unconfirmed
GUEST, unregistred user!
ImageList 不是也可以吗
 

一个过客

Unregistered / Unconfirmed
GUEST, unregistred user!
愚蠢!既然你知道需要一系列的图片TBitmap,却只Create了一个bitmap,
当然只能显示一个了,虽然你换了不同的内容。

你以为你换个马甲你就不是“剑知心”了?
 

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
我的这个程序是一个需要将许多张bitmap图片转换成一个AVI的程序,
我利用一个AVIWriter的组件,实现转换的功能,这个TAviWirter类有一个bitmaps属性
是一个Tlist指向一组Tbitmap对象的指针,通过write方法实现输出成Avi。
在这里我不能定义很多的Tbitmap的实例(因为不确定图片的数量),
既然我用Tstringlist不行能不能用定义一个不定长的Tbitmap数组,然后依次给数组的每
一个元素赋值?
//代码未调试
var
bmps : array of tbitmap;
begin
setlength(bmps, 10);//假设有10张图片
for I:=1 to 10 do
begin
bmps.loadfromfile('e:/bmp/00' + inttostr(i) + '.bmp');
end;
image1.picture.bitmap :=bmps[3];
end;
附AviWriter的属性和方法说明
// Properties: //
// Bitmaps : A TList of pointers to TBitmap objects which become //
// frames of the AVI video stream. The component //
// allocates and frees the TList, but the caller //
// is responsible for managing the TBitmaps themselves. //
// Manipulate the list as you would any other TList. //
// At least one bitmap is required. //
// Height, Width: //
// The dimensions of the AVI video, in pixels. //
// FrameTime: //
// The duration of each video frame, in milliseconds. //
// Stretch: If TRUE, each TBitmap on the Bitmaps list is //
// stretches to the dimensions specified in Height //
// and Width. If FALSE, each TBitmap is copied from //
// its upper left corner without stretching. //
// FileName: The name of the AVI file to be written. //
// WAVFileName: //
// The name of a WAV file which will become the audio //
// stream for the AVI. Optional. //
// //
// Method: //
// Write: Creates the AVI file named by FileName. //
 

一个过客

Unregistered / Unconfirmed
GUEST, unregistred user!
前面说的已经很清楚了,你把tbitmap.create放到循环里面就可以了!
难道还要我手把手的教你吗?
 

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
多谢各位,问题已经解决
 

剑知心

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
顶部