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 FileFiledialogFiledialog "Finding the PNG Dimensions", "*.*", pngFile$IfIf pngFile$ = "" Then End ' Obtain pngInfo in 3 Line InputsDimDim pngInfo$(3)OpenOpen pngFile$ for Input as #pngForFor i = 1 to 3LineLine Input #png, pngInfo$pngInfo$(i)pngInfo$(i) = pngInfo$NextNext iCloseClose #pnghiBitDechiBitDec = Asc(Mid$(pngInfo$(1), 1, 1))hiBitHex$hiBitHex$ = DecHex$(hiBitDec)ForFor i = 2 to 4NextNext iPrint:Print: Print ' Next are Bytes coded to detect the line ending conversion 'OAOA = Line Feed 'ODOD OA = Carriage Return plus Line Feed '1A1A = Stop Display of FileForFor i = 1 to 4NextNext iPrint:Print: Print ' The PNG Width is stored in the 7th and 8th Bytes of this third Line InputpngWidthpngWidth = Asc(Mid$(pngInfo$(3), 8, 1)) + Asc(Mid$(pngInfo$(3), 7, 1)) * 256pngHeightpngHeight = Asc(Mid$(pngInfo$(3), 12, 1)) + Asc(Mid$(pngInfo$(3), 11, 1)) * 256Print EndPrint End [[code]] To use this within your Liberty BASIC program, you only need the these lines [[code]] Open pngFile$ for Input as #pngLineLine Input pngSignature$LineLine Input pngLineEnd$LineLine 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]]