GFL SDK 201 on VB.NET (ASP.NET)

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Post Reply
ViTAR

GFL SDK 201 on VB.NET (ASP.NET)

Post by ViTAR »

Hello!

Since I didn't found a good solution on .NET to get image file info (such as width, height, etc.) without loading image file (or stream) into System.Drawing.Bitmap object, which may consume a lot of system resources and even crash an ASP.NET application, I'm trying to load GFL SDK gflGetFileInformation using <DllImport ...> attribute, provided by System.Runtim.InteropServices.

In such way, I could get a results from some GFL SDK methods, but not from gflGetFileInformation - .NET returns an error: Object reference not set to an instance of an object.

May be I did something wrong, but I feel that there must be something with the GFL_FILE_INFORMATION which I cannot figure out.

Do somebody may help me to resolve this problem?

VB.NET Source code used:
'''''''''''''''''''''''''''

Code: Select all

Imports System.Runtime.InteropServices
    Public Class ImageFile
        <DllImport("libgfl201.dll", _
        EntryPoint:="gflLibraryInit", _
        SetLastError:=True, _
        CharSet:=CharSet.Ansi, _
        ExactSpelling:=True, _
        CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function LibraryInit() As Integer
        End Function 'this one runs fine

        <DllImport("libgfl201.dll", _
        EntryPoint:="gflLibraryExit", _
        SetLastError:=True, _
        CharSet:=CharSet.Ansi, _
        ExactSpelling:=True, _
        CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Sub LibraryExit()
        End Sub 'this one runs fine

        <DllImport("libgfl201.dll", _
        EntryPoint:="gflGetFileInformation", _
        SetLastError:=True, _
        CharSet:=CharSet.Ansi, _
        ExactSpelling:=True, _
        CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function GetImageFileInfo(ByVal filename As String, ByVal index As Integer, ByRef information As GFL_FILE_INFORMATION) As Integer
        End Function 'this one returns ObjectNullException

        <DllImport("libgfl201.dll", _
        EntryPoint:="gflGetErrorString", _
        SetLastError:=True, _
        CharSet:=CharSet.Ansi, _
        ExactSpelling:=True, _
        CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function GetErrorString(ByVal ImageFileError As Integer) As String
        End Function 'runs fine, i could see a correct return result

        <DllImport("libgfl201.dll", _
        EntryPoint:="gflGetFormatIndexByName", _
        SetLastError:=True, _
        CharSet:=CharSet.Ansi, _
        ExactSpelling:=True, _
        CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function GetFormatIndexByName(ByVal FormatName As String) As Integer
        End Function 'this one runs fine, I could see a correct result

        Public Declare Ansi Function gflGetFileInformation Lib "libgfl201.dll" (ByVal filename As String, ByVal Index As Long, ByRef info As GFL_FILE_INFORMATION) As Integer ' this one also returns an ObjectNullException 'used to test another version of DLL method declaration - same ObjectNullException

        'This structure was reconstructed from "include/libgfl.h" as the source:
        Public Structure GFL_FILE_INFORMATION
            Public Type As System.UInt16
            Public Origin As System.UInt16
            Public Width As System.Int32
            Public Height As System.Int32
            Public FormatIndex As System.Int32
            Public FormatName As System.String
            Public Description As System.String
            Public Xdpi As System.UInt16
            Public Ydpi As System.UInt16
            Public BitsPerComponent As System.UInt16
            Public ComponentsPerPixel As System.UInt16
            Public NumberOfImages As System.Int32
            Public FileSize As System.UInt32
            Public ColorModel As System.Int32
            Public Compression As System.Int32
            Public CompressionDescription As System.String
            Public XOffset As System.Int32
            Public YOffset As System.Int32
        End Structure

    End Class

    Class ImageFileInfoTester
        Public Sub Main()
            Dim filename = "D:\somefile.jpg" 'permissions even set to everyone for test purposes
            Dim fileinfo As New ImageFile.GFL_FILE_INFORMATION
            'Dim fileinfo As ImageFile.GFL_FILE_INFORMATION 'makes no difference
            Dim result As Integer
            Images.ImageFile.LibraryInit()
            result = Images.ImageFile.GetImageFileInfo(filename, -1, fileinfo)
            Images.ImageFile.LibraryExit()
        End Sub
    End Class
''''''''''''''''
Thank you,

ViTAR
ViTAR

GFL SDK 201 on VB.NET (ASP.NET) Continued...

Post by ViTAR »

I cannot figure out how to define FormatName in GFL_FILE_INFORMATION structure. If it is defined as a String, NullReferenceException occurs (even if it is initialised as String.Empty or even a string with characters). If it is defined as Integer, other structure members are filled with unreal numbers and gflGetFileInformation will return a huge result number. Below the code I'll present the results of getting file information from "image.bmp" included with SDK.

Code: Select all

    Public Structure GFL_FILE_INFORMATION
        Public Type As GFL_BITMAP_TYPE
        Public Origin As GFL_ORIGIN
        Public Width As Integer
        Public Height As Integer
        Public FormatIndex As Integer
        Public FormatName As Integer
        Public Description As String
        Public Xdpi As Short
        Public Ydpi As Short
        Public BitsPerComponent As Short
        Public ComponentsPerPixel As Short
        Public NumberOfImages As Integer
        Public FileSize As Integer
        Public ColorModel As GFL_COLORMODEL
        Public Compression As GFL_COMPRESSION
        Public CompressionDescription As String
        Public XOffset As Integer
        Public YOffset As Integer
    End Structure

    Public Enum GFL_ERROR
        GFL_NO_ERROR = 0
        GFL_ERROR_FILE_OPEN = 1
        GFL_ERROR_FILE_READ = 2
        GFL_ERROR_FILE_CREATE = 3
        GFL_ERROR_FILE_WRITE = 4
        GFL_ERROR_NO_MEMORY = 5
        GFL_ERROR_UNKNOWN_FORMAT = 6
        GFL_ERROR_BAD_BITMAP = 7
        GFL_ERROR_BAD_FORMAT_INDEX = 10
        GFL_ERROR_BAD_PARAMETERS = 50
        GFL_UNKNOWN_ERROR = 255
    End Enum

    <Flags()> Public Enum GFL_ORIGIN As Short
        GFL_LEFT = &H0
        GFL_RIGHT = &H1
        GFL_TOP = &H0
        GFL_BOTTOM = &H10
        GFL_TOP_LEFT = GFL_TOP Or GFL_LEFT
        GFL_BOTTOM_LEFT = GFL_BOTTOM Or GFL_LEFT
        GFL_TOP_RIGHT = GFL_TOP Or GFL_RIGHT
        GFL_BOTTOM_RIGHT = GFL_BOTTOM Or GFL_RIGHT
    End Enum

    Public Enum GFL_COMPRESSION
        GFL_NO_COMPRESSION = 0
        GFL_RLE = 1
        GFL_LZW = 2
        GFL_JPEG = 3
        GFL_ZIP = 4
        GFL_SGI_RLE = 5
        GFL_CCITT_RLE = 6
        GFL_CCITT_FAX3 = 7
        GFL_CCITT_FAX3_2D = 8
        GFL_CCITT_FAX4 = 9
        GFL_WAVELET = 10
        GFL_LZW_PREDICTOR = 11
        GFL_UNKNOWN_COMPRESSION = 255
    End Enum

    Public Enum GFL_BITMAP_TYPE As Short
        GFL_BINARY = &H1
        GFL_GREY = &H2
        GFL_COLORS = &H4
        GFL_RGB = &H10
        GFL_RGBA = &H20
        GFL_BGR = &H40
        GFL_ABGR = &H80
        GFL_BGRA = &H100
    End Enum

    Public Enum GFL_COLORMODEL As Integer
        GFL_CM_RGB = 0
        GFL_CM_GREY = 1
        GFL_CM_CMY = 2
        GFL_CM_CMYK = 3
        GFL_CM_YCBCR = 4
        GFL_CM_YUV16 = 5
        GFL_CM_LAB = 6
        GFL_CM_LOGLUV = 7
        GFL_CM_LOGL = 8
    End Enum
Debugged results:

Code: Select all

GFL_FILE_INFORMATION	VALUE	TYPE
------------------------------------
BitsPerComponent	30575	Short
ColorModel	GFL_CM_RGB	ConsoleApplication1.Module1.GFL_COLORMODEL
ComponentsPerPixel	8307	Short
Compression	GFL_NO_COMPRESSION	ConsoleApplication1.Module1.GFL_COMPRESSION
CompressionDescription	Nothing	String
Description	Nothing	String
FileSize	28769	Integer
FormatIndex	4	Integer
FormatName	7368034	Integer
Height	143	Integer
NumberOfImages	1836345666	Integer
Origin	GFL_BOTTOM	ConsoleApplication1.Module1.GFL_ORIGIN
Type	-1	ConsoleApplication1.Module1.GFL_BITMAP_TYPE
Width	450	Integer
Xdpi	26967	Short
XOffset	0	Integer
Ydpi	25710	Short
YOffset	0	Integer
------------------------------------
result	1441792	Integer

Any ideas???
User avatar
xnview
Author of XnView
Posts: 43598
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: GFL SDK 201 on VB.NET (ASP.NET) Continued...

Post by xnview »

ViTAR wrote: Public Description As String
Public CompressionDescription As String
These fields are not String, but fixed size string.
I don't know how to translate char[8] in .NET!
Pierre.
Guest

Post by Guest »

i'm working on wrapping GFL in C# and i think that the correct syntax, in c# is :

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=64 )]
char[] CompressionDescription;
User avatar
xnview
Author of XnView
Posts: 43598
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Post by xnview »

Anonymous wrote:i'm working on wrapping GFL in C# and i think that the correct syntax, in c# is :

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=64 )]
char[] CompressionDescription;
Please, when you have a C# wrapper, could you send me it?
And contact me if you have problems!
Pierre.
ncoussem
Posts: 5
Joined: Tue Jun 08, 2004 3:35 pm

Post by ncoussem »

i sent you a private message about a problem that I have...
Post Reply