Please help! Error when converting byte array to image

JohanPrinsloo

Newcomer
Joined
Apr 20, 2009
Messages
10
Location
South Africa
Hi all. This is the first time I'm working with the fingerprint scanner myself. I believe it kinda works the same as all the others, it reads your fingerprint into a byte array, then I need to convert it to a system image to put it into a picturebox, or save it on a harddrive as a jpg.
I'm getting the error "Parameter is not valid." When I am trying to convert to image. Obviously I'm doing something wrong, and I'm not quite sure what. Can someone please help me in the right direction?

Visual Basic:
Public Declare Function AET60_Capture Lib "AET60.dll" (ByRef Template As Byte, ByRef TemplateLength As Integer, ByVal TimeOut As Integer) As Integer

Public iRetcode As Integer

Private Sub sbCaptureFingerprint()

Try 
   Dim iProcTimeOut As Integer
   Dim iFpTemplateLength As Integer
   Dim tmpTemplate(0 To 767) As Byte

   iProcTimeOut = 60000
   iFpTemplateLength = 768

   Dim imgByte(0 To 767) As Byte

   iRetcode = AET60_Capture(imgByte(0), iFpTemplateLength, iProcTimeOut)

   PictureBox1.Image = fConvertTo(imgByte)

Catch ex As Exception
   MsgBox(Err.Description, MsgBoxStyle.Critical, "Saving Image")
End Try

End Sub

Public Overloads Function fConvertTo(ByVal ImageArray As Byte()) As System.Drawing.Image

Dim objMS As New System.IO.MemoryStream

   objMS.Write(ImageArray, 0, ImageArray.Length)

Try

    'and this is where I get the error
   fConvertTo = System.Drawing.Image.FromStream(objMS)

Catch ae As System.ArgumentException

   fConvertTo = Nothing

End Try

End Function
 
Last edited:
All other info there is:

?Err.Description
"Parameter is not valid."

and

?ae.GetBaseException
{"Parameter is not valid."}
System.ArgumentException: {"Parameter is not valid."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: Nothing
InnerException: Nothing
Message: "Parameter is not valid."
Source: "System.Drawing"
StackTrace: " at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream) at SCARD_AUTH.frmSplash.fConvertTo(Byte[] ImageArray)"
TargetSite: {System.Reflection.RuntimeMethodInfo}

To answer you second quostion, no it is still far from a jpg. I am trying to convert it into a jpg. The fingerprintreader reads the fingerprint into the following var Dim imgByte(0 To 767) As Byte, and from there I am trying to convert it to a jpg.
 
What image format is the data in the byte array?

:confused:

That is exactly what I'm trying to do. It's not yet in a specific format. All that I can see is a few numbers. Even in the function fConvertTo in the line

objMS.Write(ImageArray, 0, ImageArray.Length)

There is still something inside ImageArray. It depends which finger, ImageArray = {4,0,0,1,1.....}
 
I also tried the following with the same results:
The error also appear at System.Drawing.Image.FromStream.
What am I doing wrong? What am I missing here?

iRetcode = AET60_Capture(imgByte(0), iFpTemplateLength, iProcTimeOut)

Dim image As Byte() = imgByte
Dim memStream As MemoryStream = New MemoryStream(image)
Dim bitImage As Bitmap = New Bitmap(System.Drawing.Image.FromStream(memStream))

bitImage.Save("C:\test.bmp")
 
Does the documentation that comes (Assuming any did) indicate what format the data is returned in? Without knowing a bit more about the actual data returned it is going to be difficult to know what to do with the data to get any image format. IIRC the .Net Image classes expect the data to be one of a limited number of formats - if this function isn't returning the data in one of these you will get problems.

Is the file at www.acs.com.hk/download/API_AET60.pdf the documentation for this device / library? If so it seems to indicate the format of the AET60_BITMAP structure in section 1.3.2. Is that correct?
 
Hi, should I use the following perhaps? But how? I am a bit lost...

Public Declare Function AET60_ConvertBitmap Lib "AET60.dll" (ByRef SampleBuffer As FBITMAP, ByRef Length As Integer, ByRef bitData As Byte) As Integer

Public Structure FBITMAP
Dim Width As Integer
Dim Height As Integer
Dim Bitmap As fDataStructure
End Structure

Public Structure fDataStructure
Dim Length As Integer
Dim Data() As Byte
End Structure
 
It looks as though that should populate the SampleBuffer with the data for the bitmap. From the documentation it looks as though the Data() is simply each byte of the image - not sure what the byte values mean though....

EDIT: If it is a DIB (which the pdf seems to indicate) then http://www.codeproject.com/KB/GDI-plus/DIBtoBitmap.aspx is probably worth a read as it should get the image into a BMP and from there you can do whatever you want with it.
 
Last edited:
Back
Top