JanetTerra JanetTerra Apr 16, 2006 - "Edited to restore Block Indentation"

[[user:JanetTerra|1145245208]] It is possible to load and display graphics in formats other than bitmap in Liberty BASIC programs. This does require the use of the atl DLL or a third party DLL such as [[http://alycesrestaurant.com/lbbrowse.htm|lbbrowse3.dll]]. Finding the dimensions of a [[http://en.wikipedia.org/wiki/PNG|Portable Network Graphics]] (PNG) file is very similar to that of getting the dimensions of a [[http://basic.wikispaces.com/BitMap+Dimensions+2/|bitmap file]]. The file must be opened and the first three Lines Inputted. The 7th, 8th, 11th and 12th Bytes of the third Line Input are then parsed for the pertinent information. [[code]] ' Choose a PNG File Filedialog Filedialog "Finding the PNG Dimensions", "*.*", pngFile$ If If pngFile$ = "" Then End ' Obtain pngInfo in 3 Line Inputs Dim Dim pngInfo$(3) Open Open pngFile$ for Input as #png For For i = 1 to 3 Line Line Input #png, pngInfo$ pngInfo$(i) pngInfo$(i) = pngInfo$ Next Next i Close Close #png Print Print ' 1st Byte is a High Bit to reduce possibility text file is mistaken for png file hiBitDec hiBitDec = Asc(Mid$(pngInfo$(1), 1, 1)) hiBitHex$ hiBitHex$ = DecHex$(hiBitDec) Print Print hiBitHex$ 'hiBitHex$ = "89" ' Next 3 Bytes are the ASCII values of P N G for easy identification of format For For i = 2 to 4 Print Print Mid$(pngInfo$(1), i, 1);" "; ' Prints P N G Next Next i Print: Print: Print ' Next are Bytes coded to detect the line ending conversion ' OA OA = Line Feed ' OD OD OA = Carriage Return plus Line Feed ' 1A 1A = Stop Display of File Print Print pngInfo$(2) Print Print ' The rest of the information follows in the third Line Input ' Each block of information is referred to as a chunk ' The first chunk in this block is always the header identified by IHDR ' Only a few of the Bytes need to be parsed to find the width and height For For i = 1 to 4 Print Print Mid$(pngInfo$(3), i, 1);" "; ' Prints I D H R Next Next i Print: Print: Print ' The PNG Width is stored in the 7th and 8th Bytes of this third Line Input pngWidth pngWidth = Asc(Mid$(pngInfo$(3), 8, 1)) + Asc(Mid$(pngInfo$(3), 7, 1)) * 256 Print Print "pngWidth = ";pngWidth Print Print ' The PNG Height is stored in the 11th and 12th Bytes of this third Line Input pngHeight pngHeight = Asc(Mid$(pngInfo$(3), 12, 1)) + Asc(Mid$(pngInfo$(3), 11, 1)) * 256 Print Print "pngHeight = ";pngHeight Print End Print End [[code]] To use this within your Liberty BASIC program, you only need the these lines [[code]] Open pngFile$ for Input as #png Line Line Input pngSignature$ Line Line Input pngLineEnd$ Line Line Input pngInfo$ Close #png pngWidth = Asc(Mid$(pngInfo$, 8, 1)) + Asc(Mid$(pngInfo$, 7, 1)) * 256 pngHeight = Asc(Mid$(pngInfo$, 12, 1)) + Asc(Mid$(pngInfo$, 11, 1)) * 256 [[code]]