Hi Martin,
Yes it is possible to read and write binary code with MapBasic (at least by
using Get And Put functions, but I don't know if that is appropriate for
your purposes).
Only thing you have to keep in mind when using Get And Put functions is that
MapInfo reads binary value as a signed value and it needs to be converted
back to unsigned original.
Other thing that makes binary handling little tricky is related to MapInfo
variables which omit a Byte (ie. 8 bit long) variable, but it can be worked
around by reading the data into for example SmallInt variable and extracting
the high and low byte values with <Mod> and <\> operators.
Besides theese limitation, binary data handling seems to work fine. It
actually works so good that I even made a fully functioning Binary Code
Editor for Mapinfo. (In case someone else needs that kind of functioning for
MI, just let me know and I will pass it to Bill Thoen)
I added a bit of code so you get the idea, even though it operates with
values smaller than 32768 so signed-unsigned conversion is not needed.
(It is a tool to invert bilevel tiff images from within MI)
Regards,
Anssi
'----------------------------------------------------------------------------
Include "mapbasic.def"
Declare Sub Main
Declare Sub Read_sub
Global fname As String
Sub Main
Dim answer As Logical
fname = FileOpenDlg("","","TIF","Invert Tiff Image")
If fname = "" Then
Exit Sub
End If
Call Read_sub
End Sub
'----------------------------------------------------------------------------
Sub Read_sub
Dim a, b, nro As SmallInt
Dim header, counter, ifd_offset,
value_offset, invert, c, d As Integer
Open File fname For Binary Access Read Write As #1
Get #1,,a
Get #1,,b
Get #1,,c
ifd_offset = c + 1
If b <> 42 Then
Note "Not a Tiff file"
End Program
Else
Get #1, ifd_offset, nro
End If
counter = 1
Do While counter <= nro
Get #1,,a
Get #1,,b
Get #1,,c
Get #1,,d
If a = 262 Then
value_offset = ifd_offset + 12 * (counter -1) + 10
If d = 0 Then
invert = 1
Put #1,value_offset, invert
Close File #1
Note "Successfully inverted"
Exit Sub
ElseIf d = 1 Then
invert = 0
Put #1,value_offset, invert
Close File #1
Note "Successfully inverted"
Exit Sub
Else Note "Not a bilevel image" + Chr$(10) + "Cannot invert"
Close File #1
Exit Sub
End If
value_offset = value_offset + 4
End If
counter = counter + 1
Loop
Close File #1
Note "Invalid Tiff file"
End Sub
'----------------------------------------------------------------------------
At 14:40 10.3.1999 +0100, you wrote:
>Hi all,
>
>Is it possible to use binary data in MapBasic?
>I'am trying to write a mapbasic application that can write (and read)
>bitmaps (.BMP files) into an Oracle Database, but MapBasic does not have
>appropriate datatypes for binding binary data (LONGROW in Oracle).
>
>According to the MapBasic User's Guide (appendix D) MapBasic supports a
>various set of ODBC datatypes, but the user's guide does not explain
>how.
>
>Does anyone know how to handle binary data in MapBasic?
>
>Thanks.
>
>Martin Vanmol
>Cegeka Industrial Systems
>[EMAIL PROTECTED]
>
>
>
>
>
>
>----------------------------------------------------------------------
>To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
>"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]
>
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]