PDA

View Full Version : Save modified DXImageList items



floken
15-09-2003, 06:13 AM
Hi,

When I draw something in a DXImageList item, and then save the list to a file it don't save it with the changes... for example:


// Open a list
DXImageList.Items.LoadFromFile('mylist1.dxg');

// Drawing something to the first image
AnotherList.Items[0].DrawAlpha(DXImageList.Items[0].PatternSurfaces[0],Bounds(0,0,100,100),0,64);

// And finally save the list
DXImageList.Items.SaveToFile('mylist2.dxg');



The mylist2.dxg remains equal to mylist1.dxg, it don't save the changes...

Please anybody could help me with it?

Thanx in advance.

Regards,
Floken

floken
15-09-2003, 03:15 PM
Please can anyone help me with this?

I made a program to create animated sprites, it fully works, but it can't save the changes :(

Why the modified items (after drawing in them) in the DXImageList don't save right?

I'm using PatternSurface to draw into the image, is that the problem? How I can draw to it in other way?

Too many questions, looking for little simple answer :)

Thanx, hope anybody could help me.

Regards,
Floken

Traveler
15-09-2003, 06:59 PM
I believe you have to use assign, but I'm not quite sure how.
Not much of a help, I know, sorry :oops:

An other idea perhaps is to save each frame to a seperate file and load them in the imagelist manually

floken
15-09-2003, 09:08 PM
I've tried to save separated items but withou success...

I think the problem is when you draw to a PatternSurface (any surface?) in the item it don't make it permanent... don't know how to explain, but after drawing if I call the method Restore it back to the original image. What I need is the opposite of Restore, something like "FixChanges" or whatever.

I've tried several "assigns" methods but without success too :(

Thx anyway :wink:

Please anybody could help me? The program is almost done, without saving :(

Regards,
Floken

cairnswm
16-09-2003, 06:03 AM
Send your program to me and I'll have a look. Zip the source and send it to william@iafrica.com

floken
16-09-2003, 07:31 AM
I've send you an example of the code I'm using, hope you could help.

Everyone who wants to try it, I've made it available at http://www.floken.com/tmp/Example.zip

Instructions:

first run the executable...

1. Draw something with the mouse.

2. Click the save button to save DXImageList2.Items to a file named "test.dxg"

3. Click the "New" button, so it clears the DXImageList2 contents...

4. Then, click the "Open" button to load "test.dxg" into DXImageList2


The problem is it don't save to the file the drawings made with the mouse.

Hope you could help, thanx a lot !!

Note: english is not my native language, hope you understand what I mean ;)

Regards,
Floken

cairnswm
17-09-2003, 05:11 AM
I can simulate exactly your problem. I think it may have something to do with locking/unlocking the surface but I havn't got it right yet.

Also it could be that a picturecollectionitem only has a pattern surface on which to draw instead of on the actual surface.

I'm still trying to find a solution :)

floken
17-09-2003, 06:13 AM
Thank you very much for trying, hope you could find a solution... I spent lots of hours with this project, but it will be useless without saving...

I've made it before using GR32 components, but I really want to use DelphiX because DX is a lot faster.

Thanx again, I'll be waiting and hoping you don't give up ;)

Best Regards,
Floken

cairnswm
23-09-2003, 05:19 AM
I havn't had another chance to look at this yet :(

I can think of a tenmporary solution but it may not quite be what you are looking for. Save the image to a bitmap (there is a thread from me in the DelphiX section on screen dumps that will show you how) - then load it back into the DXImageList.

I will still look into this sometime but I just dont have time at the moment :(

floken
23-09-2003, 01:30 PM
Well, probably I'll use that method temporarly, but it's not appropriate using it in the final project.

Anyway, thanks for trying to help me with this issue.

Regards,
Floken

www.floken.com

floken
27-09-2003, 06:49 PM
Back to what cairnswm said, I tried to experiment with the lock/unlock funtions (that's supposed to be used with pixel manipulation), but I can't Lock function work properly... any help?

I've tried:


with DXImageList.Items[0].PatternSurfaces[0] do begin

Lock(ClientRect,SurfaceDesc);

end;



The following error occurs:

"Constant object cannot be passed as var paremeter"

Hope anybody can help.

Regards,
Floken

Andreaz
27-09-2003, 07:32 PM
Just call the function

DXImageList1.Items.Restore

when you are done with the editing and it should work.

floken
27-09-2003, 09:26 PM
I've tried it before, didn't work...

...I'll apreciate if someone could make the example I've posted working.

Thanx in advance !!

Regards,
Floken

Andreaz
28-09-2003, 11:07 AM
Actually it does work, and i have tested it.




procedure TForm1.Button1Click(Sender: TObject);
begin
{
DXImageList1.Items.Add;

DXImageList1.Items[0].Name:='Base';
DXImageList1.Items[0].Picture.Bitmap.LoadFromFile('Base.bmp');
DXImageList1.Items[0].Restore;


DXImageList1.Items.SaveToFile('gfx.dxg');
}

DXImageList1.Items.LoadFromFile('gfx.dxg');
end;

floken
28-09-2003, 01:18 PM
Yes I can load from file and save to it without problems... but if I draw something into the ImageList.Item's surface, and then save the whole ImageList to a file, the drawings made to that surface don't get saved.

The strange(?) fact is the changes seems to be really made, for example, if I draw something to ImageList.Item[0].PatternSurfaces[0] , then "jump" to ImageList.Item[1].PatternSurfaces[0], and then back to ImageList.Item[0].PatternSurfaces[0], the "drawings" I made are available (I make that surface visible by drawing it to DDraw1.Surface then DDraw1.Flip).

here is some code from the example (added the "restore" line) you can download from my site:





// --- MouseMove --------------------------------------------------------------
procedure TForm1.DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin

// if left button pressed
if ssLeft in Shift then begin

// draw something into DXImageList2
DXImageList1.Items[0].DrawAlpha(DXImageList2.Items[0].PatternSurfaces[0],Bounds(x,y,2,2),0,128);
DXImageList2.Items[0].PatternSurfaces[0].Restore;

// copy it to DXDraw surface so we can see it
DXImageList2.Items[0].Draw(DXDraw.Surface,0,0,0);
DXDraw.Flip;

end;
end;



If I try to save DXImageList2.Items to file later, all "drawings" don't get saved.

Please download the example at www.floken.com/tmp/Example.zip

Thanx a lot for trying to help me !!

Best Regards,
Floken