RawLoad Example for Visual Basic
'This example loads RAW data into a LEAD control
'Raw data parameters are set in the LoadInfo event, which gets called
'when the file format is FILE_RAW, or any unrecognized file format
'The LoadInfo event obtains information through global variables
Private WithEvents RasterIO As LEADRasterIO
'Global variables used in the LoadInfo event
Dim nWidth As Integer 'width of image
Dim nHeight As Integer 'height of image
Dim nBitsPerPixel As Integer ' bits per pixel of image--if palettized, a gray palette is generated
Dim nViewPerspective As Integer 'view perspective of raw data (TOP_LEFT, BOTTOM_LEFT, etc)
Dim bOrderBGR As Integer 'TRUE if order BGR, FALSE if order RGB
Dim nOffset As Long 'offset into file where raw data begins
Dim bPadding As Boolean 'TRUE if each line of data is padded to four bytes
Dim bReverseBits As Boolean 'TRUE if the bits of each byte are reversed
Private Sub LoadRawData(szFileName As String)
Dim nRet As Integer
'Fill in the values of the global variables
'The global variables will get access in the LoadInfo event
nWidth = 294
nHeight = 415
nBitsPerPixel = 24
nViewPerspective = BOTTOM_LEFT
bOrderBGR = True
nOffset = 100
bPadding = True
bReverseBits = True
Set RasterIO = New LEADRasterIO
nRet = RasterIO.Load (LEADRasterView1.Raster, szFileName, nBitsPerPixel, 0, 1)
If (nRet = 0) Then
MsgBox ("SUCCESS file load: " & szFileName)
Else
MsgBox ("FAILED--file load: " & szFileName)
End If
End Sub
Private Sub RasterIO_LoadInfo ()
Dim nColors As Integer
Dim i As Long
Dim nGray As Long
RasterIO.LoadInfoFormat = FILE_RAW
RasterIO.LoadInfoWidth = nWidth
RasterIO.LoadInfoHeight = nHeight
RasterIO.LoadInfoBits = nBitsPerPixel
RasterIO.LoadInfoXRes = 150
RasterIO.LoadInfoYRes = 150
RasterIO.LoadInfoOffset = nOffset
RasterIO.LoadInfoFlags = 0
If (bPadding) Then
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_PAD4
End If
If (bOrderBGR = False) Then
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_ORDERRGB
End If
If (bReverseBits) Then
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_LSB
End If
Select Case nViewPerspective
Case TOP_LEFT
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT
Case BOTTOM_LEFT
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_REVERSE
Case TOP_RIGHT 'BOTTOM_LEFT180
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT180
Case BOTTOM_RIGHT 'TOP_LEFT180
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT180
Case RIGHT_TOP 'TOP_LEFT90
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT90
Case LEFT_BOTTOM 'TOP_LEFT270
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT270
Case LEFT_TOP 'BOTTOM_LEFT90
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT90
Case RIGHT_BOTTOM 'BOTTOM_LEFT270
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT270
End Select
'if image is palettized create a grayscale palette
If (nBitsPerPixel <= 8) Then
nColors = 2 ^ nBitsPerPixel
RasterIO.LoadInfoFlags = RasterIO.LoadInfoFlags Or LOADINFO_PALETTE
For i = 0 To nColors – 1
nGray = (i * 256) / nColors
RasterIO.IOPalette (i) = RGB(nGray, nGray, nGray)
Next I
End If
End Sub