F
Frederic Van Belle
Hi,
I am using in an C# application a native C DLL for image processing. The two
main functions we are using look like that :
int DLL_export _stdcall EncodeinProprietaryFormat
(
char
* i_image,
long
i_size,
char
** o_image,
long
* o_size,
);
int DLL_exporti stdcall Freeimage
(
char
** io_image
);
We manage to use those funtions with the code below :
……
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" EncodeinProprietaryFormat ")]
public static extern int EncodeinProprietaryFormat (
[In] byte[]
i_image,
[In] System.Int32 /*long*/
i_size,
[In,Out]ref IntPtr
o_image,
[In,Out] ref System.Int32
/*long*/ o_size
);
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" Freeimage†)]
public static extern int Freeimage (
[In, Out]ref IntPtr io_image
);
….
….
byte[] l_image = …..;
int l_imagesize = …. ;
IntPtr l_pointerencodedimage = IntPtr.Zero;
int l_encodedsize = 0;
byte[] l_encodedimage ;
unsafe
{
EncodeinProprietaryFormat (l_ image, imagesize, ref
l_pointerencodedimage, l_encodedsize) ;
l_ encodedimage = new byte[l_encodedsize];
for (int i = 0; i < l_encodedsize; i++)
{
l_encodedimage =
(byte)Marshal.PtrToStructure((IntPtr)((int) l_pointerencodedimage + i),
typeof(byte));
}
Freeimage (ref l_pointerencodedimage);
}
That code works but the for loop is time consuming and in the final
application we have to use that code for several million of pictures.
Is there a quickier solution ?
Best regards
Frederic Van Belle
I am using in an C# application a native C DLL for image processing. The two
main functions we are using look like that :
int DLL_export _stdcall EncodeinProprietaryFormat
(
char
* i_image,
long
i_size,
char
** o_image,
long
* o_size,
);
int DLL_exporti stdcall Freeimage
(
char
** io_image
);
We manage to use those funtions with the code below :
……
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" EncodeinProprietaryFormat ")]
public static extern int EncodeinProprietaryFormat (
[In] byte[]
i_image,
[In] System.Int32 /*long*/
i_size,
[In,Out]ref IntPtr
o_image,
[In,Out] ref System.Int32
/*long*/ o_size
);
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" Freeimage†)]
public static extern int Freeimage (
[In, Out]ref IntPtr io_image
);
….
….
byte[] l_image = …..;
int l_imagesize = …. ;
IntPtr l_pointerencodedimage = IntPtr.Zero;
int l_encodedsize = 0;
byte[] l_encodedimage ;
unsafe
{
EncodeinProprietaryFormat (l_ image, imagesize, ref
l_pointerencodedimage, l_encodedsize) ;
l_ encodedimage = new byte[l_encodedsize];
for (int i = 0; i < l_encodedsize; i++)
{
l_encodedimage =
(byte)Marshal.PtrToStructure((IntPtr)((int) l_pointerencodedimage + i),
typeof(byte));
}
Freeimage (ref l_pointerencodedimage);
}
That code works but the for loop is time consuming and in the final
application we have to use that code for several million of pictures.
Is there a quickier solution ?
Best regards
Frederic Van Belle