Array must be whole number type, two dimensional, filled with values form 0 - 255. I made it for my own needs in lack of proper alternative, so I am posting it here.. maybe it will help someone..
Code: Select all
Procedure Save8bitGrayscale (Array Matrica.i(2), Filename$)
If FileSize(Filename$) > 0
DeleteFile(Filename$)
EndIf
Fajl = OpenFile(#PB_Any, Filename$)
If Fajl = 0
ProcedureReturn 0
EndIf
DimW = ArraySize(Matrica(),1)
DimH = ArraySize(Matrica(),2)
WriteByte(Fajl, $42)
WriteByte(Fajl, $4D)
FSize = Round(4*((8*DimW + 31)/32), 0)*DimH + 1078
WriteLong(Fajl, FSize)
WriteLong(Fajl, 0)
WriteLong(Fajl, 1078)
WriteLong(Fajl, 40)
WriteLong(Fajl, DimW)
WriteLong(Fajl, DimH)
WriteWord(Fajl, 1)
WriteWord(Fajl, 8)
WriteLong(Fajl, 0)
WriteLong(Fajl, FSize-1078)
WriteLong(Fajl, 2.835)
WriteLong(Fajl, 2.835)
WriteLong(Fajl, 256)
WriteLong(Fajl, 0)
For i = 0 To 255
WriteByte(Fajl, i)
WriteByte(Fajl, i)
WriteByte(Fajl, i)
WriteByte(Fajl, 0)
Next i
For i = DimH To 0 Step -1
For m = 0 To DimW
WriteByte(Fajl, Matrica(m,i))
Next m
WriteWord(Fajl,0)
Next i
CloseFile(Fajl)
EndProcedure