Available in the LEADTOOLS Imaging toolkit. |
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.
'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
nRet = LEAD1.Load(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 LEAD1_LoadInfo()
Dim nColors As Integer
Dim i As Long
Dim nGray As Long
LEAD1.LoadInfoFormat = FILE_RAW
LEAD1.LoadInfoWidth = nWidth
LEAD1.LoadInfoHeight = nHeight
LEAD1.LoadInfoBits = nBitsPerPixel
LEAD1.LoadInfoXRes = 150
LEAD1.LoadInfoYRes = 150
LEAD1.LoadInfoOffset = nOffset
LEAD1.LoadInfoFlags = 0
If (bPadding) Then
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_PAD4
End If
If (bOrderBGR = False) Then
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_ORDERRGB
End If
If (bReverseBits) Then
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_LSB
End If
Select Case nViewPerspective
Case TOP_LEFT
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_TOPLEFT
Case BOTTOM_LEFT
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_REVERSE
Case TOP_RIGHT 'BOTTOM_LEFT180
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT180
Case BOTTOM_RIGHT 'TOP_LEFT180
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_TOPLEFT180
Case RIGHT_TOP 'TOP_LEFT90
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_TOPLEFT90
Case LEFT_BOTTOM 'TOP_LEFT270
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_TOPLEFT270
Case LEFT_TOP 'BOTTOM_LEFT90
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT90
Case RIGHT_BOTTOM 'BOTTOM_LEFT270
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_BOTTOMLEFT270
End Select
'if image is palettized create a grayscale palette
If (nBitsPerPixel <= 8) Then
nColors = 2 ^ nBitsPerPixel
LEAD1.LoadInfoFlags = LEAD1.LoadInfoFlags Or LOADINFO_PALETTE
For i = 0 To nColors - 1
nGray = (i * 256) / nColors
LEAD1.UserPalette(i) = RGB(nGray, nGray, nGray)
Next i
End If
End Sub