Images gesplittet im Code speichern von ???
Moin.

Also. Wolltet ihr schon mal ein 50(höhe)x6202(breite) images als Code Speichern? Und zwar als Array?

Selbst der BlitzBasic Compiler würde keine 6202 (im Code meine ich) langen Strings erlauben. Daher tut diese Routine das automatisch Splitten. Und das es noch nicht genüg wäre: Dieser code speicher nur die Farbwerte die auch im Bild vorkommen.

Folglich könnte man ein Bild mit über jeweils 16 mil. unterschiedliche farben speichern, wenn man es genug Splittet. Aber aufpassen: Man sollte mit der Split Funktion nicht übertreiben, denn der code wird dadurch länger. :idea:

Am besten ihr schaut euch mal dieses kleine Beispiel an:
[code:1:891de32cd8]Dim MAP_R(49), MAP_G(49), MAP_B(49), MAI$(34)
Global MA_Width, MA_Height, ActorImg[4], AP$="0123456789ABCDEFGHIJKLMNOPabcdefghijklmnopqrstuvw"

MA_Width = 46 : MA_Height = 32
MAP_R(1)=0:MAP_G(1)=0:MAP_B(1)=0
MAP_R(2)=248:MAP_G(2)=192:MAP_B(2)=96
MAP_R(3)=192:MAP_G(3)=0:MAP_B(3)=0
MAP_R(4)=248:MAP_G(4)=120:MAP_B(4)=0
MAP_R(5)=248:MAP_G(5)=252:MAP_B(5)=248
MAI$(01) = "11111111111111111113333333111111111122221111111"
MAI$(02) = "11111111111111111133333333311111111224222211111"
MAI$(03) = "11111111111111111332233322331111112242224222111"
MAI$(04) = "11111111111111113322223222233111111444242222111"
MAI$(05) = "11111111111112233222552552223221111222422242311"
MAI$(06) = "11111111111122233322532352233222111122222443311"
MAI$(07) = "11111111111122233322222222233222311111144333311"
MAI$(08) = "11111111114333222222233322222233333333344333331"
MAI$(09) = "11111111443332225522222222255223333333334333331"
MAI$(10) = "11111114333332255535553555355523333333333433331"
MAI$(11) = "11111443333332235333533353335323333333333333311"
MAI$(12) = "11114333333333225535553555355233333333333333111"
MAI$(13) = "11133333433333322225552555222333333333333311111"
MAI$(14) = "11133333344333333322222222233333333333333111111"
MAI$(15) = "11133333334443333333333333333333333333311111111"
MAI$(16) = "11133333333444322233333333333333333331111111111"
MAI$(17) = "11113333333333322222433424242343333311111111111"
MAI$(18) = "11111333333333332322244222224334333111111111111"
MAI$(19) = "11111133333333333222244222222443333111111111111"
MAI$(20) = "11111111133333332322244222322443333111111111111"
MAI$(21) = "11111114444334422222422422222434334111111111111"
MAI$(22) = "11111443333333344444222244444343333411111111111"
MAI$(23) = "11114333333333334222222222243333333341111111111"
MAI$(24) = "11114333333334334242422424243333333334111111111"
MAI$(25) = "11113333333333333424242342433333333333411111111"
MAI$(26) = "11113333333333334334343343343333333333411111111"
MAI$(27) = "11133333333333331111111111333333333333411111111"
MAI$(28) = "12223333333311111111111111133333333333111111111"
MAI$(29) = "22232223333111111111111111113333333333111111111"
MAI$(30) = "22222232222111111111111111111232233322321111111"
MAI$(31) = "11111111111111111111111111111223222232242111111"
MAI$(32) = "11111111111111111111111111111122222222224211111"
MAI$(33) = "11111111111111111111111111111111111111111111111"
MakeActorImage 1

MA_Width = 46 : MA_Height = 32
MAP_R(1)=0:MAP_G(1)=0:MAP_B(1)=0
MAP_R(2)=192:MAP_G(2)=0:MAP_B(2)=0
MAP_R(3)=248:MAP_G(3)=192:MAP_B(3)=96
MAP_R(4)=248:MAP_G(4)=120:MAP_B(4)=0
MAP_R(5)=248:MAP_G(5)=252:MAP_B(5)=248
MAI$(01) = "11111133331111111111222222211111111111111111111"
MAI$(02) = "11113333433111111112222222221111111111111111111"
MAI$(03) = "11333433343311111122332223322111111111111111111"
MAI$(04) = "11333343444111111223333233332211111111111111111"
MAI$(05) = "12343334333111133233355355333223311111111111111"
MAI$(06) = "12244333331111333223352325332223331111111111111"
MAI$(07) = "12222441111112333223333333332223331111111111111"
MAI$(08) = "22222442222222223333332223333333222411111111111"
MAI$(09) = "22222422222222233553333333335533322244111111111"
MAI$(10) = "22224222222222235552555255525553322222411111111"
MAI$(11) = "12222222222222232522252225222523322222244111111"
MAI$(12) = "11222222222222223552555255525533222222222411111"
MAI$(13) = "11112222222222222333555355533332222224222221111"
MAI$(14) = "11111222222222222223333333332222222442222221111"
MAI$(15) = "11111112222222222222222222222222244422222221111"
MAI$(16) = "11111111122222222222222222223332444222222221111"
MAI$(17) = "11111111112222242343434224333332222222222211111"
MAI$(18) = "11111111111222422433333443332322222222222111111"
MAI$(19) = "11111111111222244333333443333222222222221111111"
MAI$(20) = "11111111111222244332333443332322222221111111111"
MAI$(21) = "11111111111422424333334334333334422444411111111"
MAI$(22) = "11111111114222242444443333444442222222244111111"
MAI$(23) = "11111111142222222243333333333422222222222411111"
MAI$(24) = "11111111422222222243434334343422422222222411111"
MAI$(25) = "11111114222222222224342343434222222222222211111"
MAI$(26) = "11111114222222222242242242422422222222222211111"
MAI$(27) = "11111114222222222222111111111122222222222221111"
MAI$(28) = "11111111222222222221111111111111112222222233311"
MAI$(29) = "11111111222222222211111111111111111222233323331"
MAI$(30) = "11111132332223323111111111111111111333323333331"
MAI$(31) = "11111343323333233111111111111111111111111111111"
MAI$(32) = "11113433333333331111111111111111111111111111111"
MAI$(33) = "11111111111111111111111111111111111111111111111"
MakeActorImage 2

MA_Width = 46 : MA_Height = 32
MAP_R(1)=0:MAP_G(1)=0:MAP_B(1)=0
MAP_R(2)=248:MAP_G(2)=192:MAP_B(2)=96
MAP_R(3)=248:MAP_G(3)=120:MAP_B(3)=0
MAP_R(4)=192:MAP_G(4)=0:MAP_B(4)=0
MAP_R(5)=248:MAP_G(5)=252:MAP_B(5)=248
MAI$(01) = "11111111111111111114444444111111111111111111111"
MAI$(02) = "11111111111111111144444444411111111111111111111"
MAI$(03) = "11111111111111111442244422441111111111111111111"
MAI$(04) = "11111111111111114422224222244111111111111111111"
MAI$(05) = "11111111111112244222552552224422111111111111111"
MAI$(06) = "11111111111122244422542452244422211111111111111"
MAI$(07) = "11111111111122244422222222244422211111111111111"
MAI$(08) = "11111111113444222222244422222224443111111111111"
MAI$(09) = "11111111334442225522222222255222444331111111111"
MAI$(10) = "11111113444442255545554555455522444443111111111"
MAI$(11) = "11111334444442245444544454445422444444331111111"
MAI$(12) = "11113444444444225545554555455224444444443111111"
MAI$(13) = "11144444344444422225552555222244444434444411111"
MAI$(14) = "11144444433444444422222222244444443344444411111"
MAI$(15) = "11144444443334444444444444444444333444444411111"
MAI$(16) = "11144444444333422244444444422243334444444411111"
MAI$(17) = "11114444444444422222344432222244444444444111111"
MAI$(18) = "11111444444444442422233322242444444444441111111"
MAI$(19) = "11111144444444444222233322224444444444411111111"
MAI$(20) = "11111111144444442422233322242444444411111111111"
MAI$(21) = "11111113333443322222322232222233443333111111111"
MAI$(22) = "11111334444444433333222223333344444444331111111"
MAI$(23) = "11113444444444443222222222223444444444443111111"
MAI$(24) = "11113444444443443232322232323443444444443111111"
MAI$(25) = "11114444444444444323232323234444444444444111111"
MAI$(26) = "11114444444444443443434343443444444444444111111"
MAI$(27) = "11144444444444441111111111111444444444444411111"
MAI$(28) = "11114444444444411111111111111144444444444111111"
MAI$(29) = "11114444444444111111111111111114444444444111111"
MAI$(30) = "11242244422421111111111111111111242244422421111"
MAI$(31) = "12322422224221111111111111111111224222242232111"
MAI$(32) = "23222222222211111111111111111111122222222223211"
MAI$(33) = "11111111111111111111111111111111111111111111111"
MakeActorImage 3

Function MakeActorImage(AI)
If ActorImg[AI] = 0 Then
ActorImg[AI] = CreateImage(MA_Width*2, MA_Height*2)
SetBuffer ImageBuffer(ActorImg[AI])
Else
newpic = CreateImage(ImageWidth(ActorImg[AI])+MA_Width*2, MA_Height*2)
SetBuffer ImageBuffer(newpic)
DrawImage ActorImg[AI], 0, 0
ZW = ImageWidth(ActorImg[AI]) - 2
FreeImage ActorImg[AI]
ActorImg[AI] = newpic
End If
For AIDy = 1 To MA_Height
For AIDx = 1 To MA_Width
MyCS$ = Mid$(MAI$(AIDy), AIDx, 1) : FromPal = Instr(AP$, MyCS$, 1)
Color MAP_R(FromPal-1), MAP_G(FromPal-1), MAP_B(FromPal-1)
Plot AIDx*2+ZW, AIDy*2 : Plot AIDx*2+ZW, AIDy*2+1
Plot AIDx*2+1+ZW, AIDy*2 : Plot AIDx*2+1+ZW, AIDy*2+1
Next
Next
End Function

Anim = 1
SetBuffer BackBuffer()
oldsec = MilliSecs()
While Not KeyHit(1)
Color 0, 0, 0 : Rect 0, 0, 100, 100
If MilliSecs() > oldsec + 200 Then oldsec = MilliSecs() : Anim = Anim + 1 : If Anim > 3 Then Anim = 1

; anim =3
DrawImage ActorImg[Anim], 0, 0

Flip 0
Wend

End[/code:1:891de32cd8]


Hier ist nun der Code zum Erstellen der Bilder:
[code:1:891de32cd8]Graphics 640,480,16,2 : SetBuffer BackBuffer()
Global MakePallets$ = "0123456789ABCDEFGHIJKLMNOPabcdefghijklmnopqrstuvw"

Const SaveLenght = 50

Global MyImg = 1

Type Pal
Field R, G, B
End Type

Global FH = WriteFile("graph.bb")

Global MyFile = 1, MaxH : Progess = 1
While Progess
If FileType("graph" + MyFile + ".bmp") Then
img = LoadImage("graph" + MyFile + ".bmp")
If ImageHeight(img)>MaxH Then MaxH = ImageHeight(img)
FreeImage img

MyFile = MyFile + 1
Else
Progess = 0
End If
Wend

WriteLine FH, "Dim MAP_R(" + Len(MakePallets$) + "), MAP_G(" + Len(MakePallets$) + "), MAP_B(" + Len(MakePallets$) + "), MAI$(" + (MaxH+2) + ")"
WriteLine FH, "Global MA_Width, MA_Height, ActorImg[" + MyFile + "], AP$=" + Chr$(34) + "0123456789ABCDEFGHIJKLMNOPabcdefghijklmnopqrstuvw" + Chr$(34)
WriteLine FH, ""

MyFile = 1 : Progess = 1
While Progess
If FileType("graph" + MyFile + ".bmp") Then
img = LoadImage("graph" + MyFile + ".bmp")
AddImage img
FreeImage img

MyFile = MyFile + 1
Else
Progess = 0
End If
Wend

WriteLine FH, "Function MakeActorImage(AI)"
WriteLine FH, " If ActorImg[AI] = 0 Then"
WriteLine FH, " ActorImg[AI] = CreateImage(MA_Width*2, MA_Height*2)"
WriteLine FH, " SetBuffer ImageBuffer(ActorImg[AI])"
WriteLine FH, " Else"
WriteLine FH, " newpic = CreateImage(ImageWidth(ActorImg[AI])+MA_Width*2, MA_Height*2)"
WriteLine FH, " SetBuffer ImageBuffer(newpic)"
WriteLine FH, " DrawImage ActorImg[AI], 0, 0"
WriteLine FH, " ZW = ImageWidth(ActorImg[AI]) - 2"
WriteLine FH, " FreeImage ActorImg[AI]"
WriteLine FH, " ActorImg[AI] = newpic"
WriteLine FH, " End If"
WriteLine FH, " For AIDy = 1 To MA_Height"
WriteLine FH, " For AIDx = 1 To MA_Width"
WriteLine FH, " MyCS$ = Mid$(MAI$(AIDy), AIDx, 1) : FromPal = Instr(AP$, MyCS$, 1)"
WriteLine FH, " Color MAP_R(FromPal-1), MAP_G(FromPal-1), MAP_B(FromPal-1)"
WriteLine FH, " Plot AIDx*2+ZW, AIDy*2 : Plot AIDx*2+ZW, AIDy*2+1"
WriteLine FH, " Plot AIDx*2+1+ZW, AIDy*2 : Plot AIDx*2+1+ZW, AIDy*2+1"
WriteLine FH, " Next"
WriteLine FH, " Next"
WriteLine FH, "End Function"

CloseFile FH

Flip
;WaitKey
End

Function AddImage(img)
Local imgb
mww = ImageWidth(img) : If mww>SaveLenght Then mww = SaveLenght
WriteLine FH, "MA_Width = " + mww + " : " + "MA_Height = " + ImageHeight(img)
SetBuffer ImageBuffer(img)
For X = 0 To ImageWidth(img)
For Y = 0 To ImageHeight(img)
GetColor X, Y
MakePal = 1
For P.Pal = Each Pal
If PR = ColorRed() And PG = ColorGreen() And PB = ColorBlue() Then MakePal = 0
Next

If MakePal = 1 Then
P.Pal = New Pal
PR = ColorRed()
PG = ColorGreen()
PB = ColorBlue()
End If
Next
Next

MakePal = 1
For P.Pal = Each Pal
WriteLine FH, "MAP_R("+MakePal+")="+PR+":MAP_G("+MakePal+")="+PG+":MAP_B("+MakePal+")="+PB
MakePal = MakePal + 1
Next

ILine = 0
For Y = 0 To ImageHeight(img)
MLine$ = "" : ILine = ILine + 1
tobigl = 0
For X = 0 To ImageWidth(img)
GetColor X, Y : MakePal = 1
For P.Pal = Each Pal
If PR = ColorRed() And PG = ColorGreen() And PB = ColorBlue() Then
If Len(MLine$) < SaveLenght Then MLine$ = MLine$ + Mid$(MakePallets$, MakePal + 1, 1)
If Not Len(MLine$) < SaveLenght Then tobigl = 1
End If
MakePal = MakePal + 1
Next
Next

If ILine < 10 Then
WriteLine FH, "MAI$(0"+ILine+") = " + Chr$(34) + MLine$ + Chr$(34)
Else
WriteLine FH, "MAI$("+ILine+") = " + Chr$(34) + MLine$ + Chr$(34)
End If
Next

Delete Each Pal

WriteLine FH, "MakeActorImage " + MyImg
WriteLine FH, ""

If tobigl = 1 Then
imgb = CreateImage(ImageWidth(img)-SaveLenght, ImageHeight(img))
SetBuffer ImageBuffer(imgb)
DrawImage img, -SaveLenght, 0
AddImage imgb
FreeImage imgb
Else
MyImg = MyImg + 1
End If
End Function[/code:1:891de32cd8]



Suche:
(unterstützt mySQL Wildcards ala %)
Titel:
Text:
Autor: