Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type BMPFileHeader (strFileType() As Byte, FileSize() As Byte, bReserved1() As Byte,bReserved2() As Byte,BitmapOffset() As Byte)
Type BMPInfo (biSize() As Byte, biWidth() As Byte, biHeight() As Byte, biPlanes() As Byte, biBitCount() As Byte, Bicompression() As Byte, biSizeImage() As Byte, biXpelsPerMeter() As Byte, biYpelsPerMeter() As Byte, BiClrUsed() As Byte, biClrImportant() As Byte)
Type BMPPalette (lngBlue As Byte,lngGreen As Byte,lngRed As Byte,lngReserved As Byte)
End Sub
Sub bmpGenerate (imagedata() As Byte,width As Int,Height As Int)
Private bc As ByteConverter
bc.LittleEndian=True
Private header As BMPFileHeader
Private Info As BMPInfo
'** HEADER **
header.strFileType=bc.HexToBytes("424D")
header.FileSize=bc.IntsToBytes(Array As Int (54 + 1024 + width * Height))
header.bReserved1=bc.ShortsToBytes(Array As Short (0))
header.bReserved2=bc.ShortsToBytes(Array As Short(0))
header.BitmapOffset=bc.intsToBytes(Array As Int (54 + 1024))
'** HEADER iNFO ***
Info.biSize=bc.IntsToBytes(Array As Int (40))
Info.biWidth=bc.intsToBytes(Array As Int(width))
Info.biHeight=bc.intsToBytes(Array As Int(Height))
Info.biPlanes=bc.ShortsToBytes(Array As Short (1))
Info.biBitCount=bc.ShortsToBytes(Array As Short (8))
Info.Bicompression=bc.intsToBytes(Array As Int (0))
Info.biSizeImage=bc.intsToBytes(Array As Int(width*Height))
Info.biXpelsPerMeter=bc.intsToBytes(Array As Int(0))
Info.biYpelsPerMeter=bc.intsToBytes(Array As Int(0))
Info.BiClrUsed=bc.intsToBytes(Array As Int(256))
Info.biClrImportant=bc.intsToBytes(Array As Int(0))
Private palette(1024) As Byte
For i=0 To 255
palette(i*4)=i
palette(i*4+1)=i
palette(i*4+2)=i
palette(i*4+3)=0
Next
'** Write header
Dim bmpfile As RandomAccessFile
bmpfile.Initialize(File.DirRootExternal,"testebmp.bmp",False)
bmpfile.WriteBytes(header.strFileType,0,header.strFileType.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(header.filesize,0,header.FileSize.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(header.bReserved1,0,header.bReserved1.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(header.bReserved2,0,header.bReserved2.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(header.BitmapOffset,0,header.BitmapOffset.Length,bmpfile.CurrentPosition)
'** Write info
bmpfile.WriteBytes(Info.biSize,0,Info.biSize.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biWidth,0,Info.biWidth.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biHeight,0,Info.biHeight.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biPlanes,0,Info.biPlanes.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biBitCount,0,Info.biBitCount.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.Bicompression,0,Info.Bicompression.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biSizeImage,0,Info.biSizeImage.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biXpelsPerMeter,0,Info.biXpelsPerMeter.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biYpelsPerMeter,0,Info.biYpelsPerMeter.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.BiClrUsed,0,Info.BiClrUsed.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(Info.biClrImportant,0,Info.biClrImportant.Length,bmpfile.CurrentPosition)
bmpfile.WriteBytes(palette,0,palette.Length,bmpfile.CurrentPosition)
'** Write palete
bmpfile.WriteBytes(palette,0,palette.Length,bmpfile.CurrentPosition)
'** Write imagedata
bmpfile.WriteBytes(imagedata,0,imagedata.Length,bmpfile.CurrentPosition)
bmpfile.Close
End Sub