saving images and text all in one file
Posted: Mon Dec 29, 2003 4:05 am
ive posted once or twice about saving a set of images and text or gadget states all in one file. the replies i got talked about using the packfile command. i didnt like that one too much, and figured another way to do it. i have a rather complex program to store data and images for my PHD dissertation, and wanted to have a single file for the data. so i worked up a way to save images and text into a modified JPEG file.
basically, with a jpeg you can write text to the file provided it in in the INI format where brackets surround the headings. i think the OS just overlooks these because you can open the file in either any image editor OR open it up in notepad and read the INI part too. it works amazingly for me. i have about 60 270x180 pictires that i write to a big JPEG in a grid layout, and then write all my text to the same file in an INI format. then when i open the file, i grab the loaded image (270x180) and set an image gadget state with it. sorry if this isnt the best format, but i really wanted to share!!!!!
Code: Select all
Procedure savehybridfile()
Filename$=SaveFileRequester("Please choose file to save","","Database|*.dr2",0)
files$=GetExtensionPart(Filename$)
If files$="dr2"
mainfile$=Filename$
Else
mainfile$=Filename$ + ".dr2"
EndIf
If mainfile$=""
MessageRequester("Error","File Name Is Needed Or User Canceled", #PB_MessageRequester_Ok)
endif
width=10*270
height=6*300
CreateImage(0,width,height)
StartDrawing(ImageOutput())
;Here we get all the images of the program in different image gadgets
For d=#Image_9 To #Image_98
;These are my image gadget constants,whose image# is the same as
;the gadget constant
If d=#Image_9
xloc=0
yloc=0
hght=180
ElseIf d=#Image_10
xloc=271
yloc=0
ElseIf d=#Image_19
xloc=0
yloc=181
ElseIf d=#Image_20
xloc=271
yloc=181
ElseIf d=#Image_29
xloc=0
yloc=391
ElseIf d=#Image_30
xloc=271
yloc=391
ElseIf d=#Image_39
xloc=0
yloc=601
ElseIf d=#Image_40
xloc=271
yloc=601
ElseIf d=#Image_49
xloc=0
yloc=811
ElseIf d=#Image_50
xloc=271
hght=180
ElseIf d=#Image_59
xloc=0
yloc=1021
ElseIf d=#Image_60
xloc=271
yloc=1021
ElseIf d=#Image_69
xloc=0
yloc=1231
ElseIf d=#Image_70
xloc=271
yloc=1231
ElseIf d=#Image_79
xloc=0
yloc=1411
ElseIf d=#Image_80
xloc=271
yloc=1411
ElseIf d=#Image_89
xloc=0
yloc=1591
ElseIf d=#Image_90
xloc=271
yloc=1591
EndIf
DrawImage(UseImage(d),xloc,yloc,270,180)
xloc=xloc+270
Next
StopDrawing()
SaveImage(0, mainfile$,#PB_ImagePlugin_JPEG,10)
;Now we write gadget states and text to the same JPEG file
Repeat
gad=gad+1
If GetGadgetState(gad)=1 ;GADGET STATES,is it checked or no?
writeINI(tabname$,Str(gad),"yes",[b]mainfile$[/b])
ElseIf GetGadgetState(gad)=0
writeINI(tabname$,Str(gad),"no",mainfile$)
EndIf
Until gad=43
Repeat
gad=gad+1
Text$=GetGadgetText(gad) ;GADGET TEXT
writeINI(tabname$,Str(gad),Text$,[b]mainfile$[/b])
Until gad=55
endprocedure