PDA

View Full Version : DXImagelist > LoadFromFile & SaveToFile



Smok
27-07-2006, 11:52 AM
I want to create simple tile-package editor. It has to load pictures into DXImageList, and save them into one file.

I was trying to do such thing:


procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
if FileExists('test.gfx') then
IL.Items.LoadFromFile('test.gfx');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IL.Items.SaveToFile('test.gfx');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Item: TPictureCollectionItem;
picture : TPicture;
begin
if openDlg.Execute then
begin
picture := TPicture.Create;
picture.LoadFromFile(openDlg.Filename);
try
Item := TPictureCollectionItem.Create(IL.Items);
Item.Picture.Graphic := picture.Graphic;
Item.Name:=InputBox('Name','Name:','');
Item.Restore;
finally
picture.Free;
end;
end;
end;


But package files never get saved or loaded. (I've got images in imagelist, cause I can draw them).

This SaveToFile works only when I add images to component (before running application). After such save it is possible to load these images back to component.

I don't know to add or replace image. Deleting existing images works fine.

How can I dynamically add images _and_ save them?

Speeeder
02-08-2006, 01:50 PM
uhm, haven't used DXImageLists for any dinamic loading, buuut... I faintly remember having to load to a DIB object and put the image in from there... However for dinamicly loading pics, I'd say you should use a list of TDirectDrawSurfaces... You can work with them more or less how you'd work with TBitmaps and the Windows Canvas... (In other words, using the DXDraw1.Surface methods to draw, supplying a TDirectDrawSurface)