UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: XpMe_v1.2 on December 18, 2004, 01:27:21 PM

Title: Small bitmap images to Data file
Post by: XpMe_v1.2 on December 18, 2004, 01:27:21 PM
This puts 60 24x24y images into 1 data file.
Sizes can be change if needed.

[pbcode]
` This example uses 60  24x24y images which can be changed.
` Designed for small images.  You provide the bitmap images.  
` Just don't go off screen.

` Your bitmaps needs loaded as "01.bmp to 60.bmp".
` Notice that 1 to 9 needs a zero first before the number.
` Unless you edit the code.

Type Squares
files  As String
cnt    As Integer
bmp    As Integer
got    As Integer
idx    As Integer
w      As Integer
d      As Integer
EndType
Dim Im As Squares
Im.files = CurrentDir$() + "YourName.dat"    ` the DATA file name
If FileExist(Im.files) Then DeleteFile Im.files
Im.bmp = 1   ` load  images
Im.got = 90  ` final images
Im.idx = 1   ` file access number
Im.cnt = 60  ` number of images to be used
Im.w   = 25  ` image width  24+1
Im.d   = 25  ` image height 24+1
Dim Images(Im.cnt ,Im.w,Im.d)
`------
OpenScreen 280,450,32,1
CenterScreen           : LoadYourImages()    : SaveData()     : LoadData()
Cls RGB(225,255,235)   : DrawDataImages(5,9) : GetImages(5,9) : PutImages(5,230)
Sync : Repeat : Until LeftMouseButton() : END
`------
Function LoadYourImages()
TitleScreen "Load Your Images" : For t = 1 To Im.cnt : LoadImage ImageNames(t), Im.bmp + t : Next :Delays(444)
EndFunction
`------
Function SaveData()
TitleScreen "Load Images + Save to Data File"
  WriteFile Im.files ,Im.idx
For t = 1 To Im.cnt : Cls 0 : DrawImage Im.bmp + t, 1,1,1     :Delays(5)
For y = 1 To Im.w :For x = 1 To Im.d : WriteString Im.idx,Str$(Point(x,y)) :Next :Next :Next : CloseFile Im.idx
EndFunction
`------
Function LoadData()
TitleScreen "Re-load Data File"
ReadFile Im.files ,Im.idx
For t = 1 To Im.cnt : For y=1 To Im.w : For x=1 To Im.d : a$=ReadString$(Im.idx) : Images(t,x,y)=Val(a$)
Next :Next :Delays(5): Next : CloseFile Im.idx
EndFunction
`------
Function DrawDataImages(xx,yy)
TitleScreen "Draw shapes from Data File"
n = 1 : ix=xx : For t = 1 To Im.cnt : For y = 1 To Im.w : For x = 1 To Im.d : DotC ix+x,yy+y, Images(t,x,y)
Next :Next  :Delays(5): ix=ix+Im.w+5: Inc n:  If n = 10 Then n = 1 : ix=xx : yy=yy+Im.d+5
Next
EndFunction
`------
Function GetImages(xx,yy)
n = 1 : ix=xx : For t = 1 To Im.cnt : GetImage Im.got + t ,ix  ,yy ,ix+Im.w ,yy+Im.d  :Delays(45)
       ix=ix+Im.w+5 :Inc n:  If n = 10 Then n = 1 :ix=xx : yy=yy+Im.d+5
TitleScreen "Get drawn shapes into images " + Str$(t)
Next
EndFunction
`------
Function PutImages(xx,yy)
TitleScreen "Put images below drawn data images"
n = 1 : ix=xx : For t = 1 To Im.cnt : DrawImage Im.got + t ,ix ,yy ,1     :Delays(5)
       ix=ix+Im.w+5  :Inc n:  If n = 10 Then n = 1 :ix=xx: yy=yy+Im.d+5
Next
EndFunction
`------
Psub ImageNames(n)
s$ = "" : If n < 10 Then s$ = "0"
EndPsub s$ + Str$(n) + ".bmp"
`------
Psub Delays(n)
Wait n : Sync
EndPsub
`------end of source
[/pbcode]


  Related Source Codes:

      Storing Images in data statements (https://www.underwaredesign.com/forums/index.php?topic=2245.0)