3

I am using NITGEN's Fingkey Hamster DX for capturing a finger print.

I have converted the fingerprint data to a text format which gives me a string like the following (string "sr" in below code gives this string):

AQAAABQAAAAEAQAAAQASAAEAZAAAAAAA*AAAAOHbWlAewfLK7kOnScKzeN5HMVcDmjce0KPkeqyeiWEdTnJutHvnhyrnkW9OPbQNQc7/94lnozdd3Zz8RKiRSj8HHdCMZ8XIdaCy0tCxp2wLwRbVrHl14QkJlQMGqeJyzu06h/ZorwN5vVoxuzFDM9dKyqlm85XHuOeoeACxO/xZrE3NdH4aesbYWgy2i5Cru2AHymemLVeu7BX5BRgFkRrx6JzcZpW9Jn0r3GOkdSqGZG85soUxNX4GN*4gJlqjfCg81cDZAi5NqiEosZjJUXwZ2677ll3OCOUaS31/7v7qF9NN1XdlNc1hrI8kQfmtbRNM3EOybwAoFTHG76rqRos

I have tried to convert this string into a byte[] array using following code :

textFIR = new NBioAPI.Type.FIR_TEXTENCODE();
UInt32 r = m_NBioAPI.GetTextFIRFromHandle(hCapturedFIR, out textFIR, true);

string sr = "";
if (textFIR != null)
{
    sr = textFIR.TextFIR;
    byte[] src = new byte[sr.Length*sizeof(char)];

    System.Buffer.BlockCopy(sr.ToCharArray(),0,src,0,src.Length);
    MemoryStream ms = new MemoryStream(src);
    System.Drawing.Image FP = System.Drawing.Image.FromStream(ms);
    FP.Save("G:\\TempFP.Jpeg", ImageFormat.Jpeg);
}

But on Image.FromStream(ms) I am getting "Parameter is not valid." exception.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Touhid K.
  • 31
  • 1
  • 5
  • possible duplicate of [.NET String to byte Array C#](http://stackoverflow.com/questions/472906/net-string-to-byte-array-c-sharp) – slugster Sep 07 '13 at 04:54
  • Also: http://stackoverflow.com/q/14360257/109702, http://stackoverflow.com/q/11730373/109702, – slugster Sep 07 '13 at 04:56
  • "I have converted the fingerprint data to a text format" - What type was the fingerprint data to begin with? a byte array? – Mitch Wheat Sep 07 '13 at 04:57
  • No they dont provide a simple byte array. They want users to play with their TYPES only. – Touhid K. Sep 07 '13 at 05:03
  • I am uising NITGEN's NITGEN.SDK.NBioBSP..And the fingerprint data type is "NBioAPI.Type.HFIR hCapturedFIR". And "m_NBioAPI.Capture(out hCapturedFIR, NBioAPI.Type.TIMEOUT.DEFAULT, m_WinOption)" this line gives hCapturedFIR. – Touhid K. Sep 07 '13 at 05:12
  • Are you sure that the data in textFIR.TextFIR is an image, and not some form of fingerprint description data? Those bytes don't look like a BMP header or JPEG file preamble. – dthorpe Sep 07 '13 at 05:17
  • This is what I found in NITGEN's developer guide : All fingerprint data is used as the type of handle, binary or encoded text found in the NBioBSP Class Library module. Fingerprint data will be entered into the handle of FIR property upon successful enrollment, and it can be returned as the type of binary or encoded text. So textFIR is an encoded Fingerprint data, I suppose. Do you know any other SDK which prvides APIs to convert finger print data to byte array or a JPEG form? – Touhid K. Sep 07 '13 at 05:36
  • Take the image and save it to your file system called foo.jpg and double click on it. If you can't open it then it's not in any recognized image format. Windows will open .png and .gif files even if they are called something.jpg. – dcaswell Sep 07 '13 at 05:40
  • You can also check file formats by looking at through first few bytes of the file and matching them here: http://www.garykessler.net/library/file_sigs.html – dcaswell Sep 07 '13 at 05:41

4 Answers4

1

Though I don't have experience with the particular library you're using, I can see some obvious problems with your code and expect them to be causing the issue. Check these two lines of your code:

string sr = "";
byte[] src = new byte[sr.Length*sizeof(char)];

sr is an empty string at this time, so sr.Length will be zeroand the byte array will also be zero-length, therefore BlockCopy will not be able to write anything to it. You should move this second line inside the if block, after the line sr = textFIR.TextFIR;.

dotNET
  • 33,414
  • 24
  • 162
  • 251
  • I tried what you told me to do. But it still gives me the same exception. Parameter is not Valid. – Touhid K. Sep 07 '13 at 05:00
  • I am not sure abut that..Because textFIR is an object which encodes actual finger print data (NBioAPI.Type.HFIR) into a text. – Touhid K. Sep 07 '13 at 05:22
  • I just went through their documentation (http://www.nitgen.com.br/download/EN_eNBSP_SDK_Programmer's_Guide_DC1-0017A_Rev_J.pdf). Looks like there's more to it than simply converting into a memory stream. Nowhere do they mention the exact image format they are using. – dotNET Sep 07 '13 at 05:49
  • Any idea on this dotNET? I am stuck on this since last week. I would really appreciate your help. – Touhid K. Sep 07 '13 at 06:07
  • Try Tejas's idea. I don't have either the hardware or the software with me, so it is a bit difficult for me to experiment with it. – dotNET Sep 07 '13 at 06:19
1

The text in TextFIR member is neither a valid base64 encoded data or an image data. It is a multi-byte text data used to store and verify with other FIR.

Use the API in NImgConv.dll to get an image from the FIR data.

Vijay Sirigiri
  • 4,653
  • 29
  • 31
  • But NImgConv.dll is written in cpp and delphi. I dont have its c# classes. the version of my Sdk is 3.12. It doe not include c# classes for this. Have u done this in c#? Can u send me an example code if u have done this? – Touhid K. Sep 07 '13 at 06:20
  • If it is a COM component then regsvr32 NImgConv.dll and add ref from COM tab in VS otherwise follow the instructions http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-sharp-application – Vijay Sirigiri Sep 07 '13 at 06:25
  • I am new to .NET and developing field. I tried regsvr32 NImgConv.dll And got following error : The module "NImgConv.dll" was loaded but entry-point DllRegister was not found. Make sure that NImgConv.dll is a valid DLL or OCX file and try again. Any Idea? I did not get the second option. – Touhid K. Sep 07 '13 at 06:40
  • It might not be a COM component; try following the instructions from the url http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-sharp-application – Vijay Sirigiri Sep 07 '13 at 06:49
  • I am sorry but I dont even have an option for creating C++/CLI projects in my VS. I am totally new to this. – Touhid K. Sep 07 '13 at 07:01
  • Ok..I get it..I have to create a class library project. i have created it. But how to make it depend on unmanaged dll? – Touhid K. Sep 07 '13 at 07:09
0

You should try FromBase64string method to convert it to byte array.

public static  byte[] StringToBytes(string streamString)
{
   return Convert.FromBase64String(streamString);
}

To make sure your base64string is valid, you can check it like

<img alt="" src="data:image/jpeg;base64,**your base 64 string**" />

Check out this link for more info.

Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43
  • I got following exception on trying to do this : The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. – Touhid K. Sep 07 '13 at 05:43
0

I think you got the string is in Base64 format, so you can use this functions to convert your string to Bytes[] and then use another function to convert Bytes[] to image.

    internal bool SaveBytesToFile(string fileFullPath, byte[] stream)
    {
        if (stream.Length == 0) return false;
        try
        { 
            try
            {
                using (FileStream fileStream = System.IO.File.Create(fileFullPath, (int)stream.Length))
                {
                    fileStream.Write(stream, 0, stream.Length);
                }
            }
            catch (Exception ex)
            {
                //Write Error log
                errorhandler.Write(ex);
                return false;
            }

            return true;
        }
        catch (Exception ex)
        {
            //Write Error log
            errorhandler.Write(ex);
            return false;
        }

    }

    internal byte[] StringToBytes(string streamString)
    {
        return Convert.FromBase64String(streamString);
    }

    internal string BytesToString(byte[] stream)
    {
        return Convert.ToBase64String(stream);
    }
Tejas Vaishnav
  • 466
  • 5
  • 20
  • I can not convert this string to byte array. I get following exception on trying to do this : The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters – Touhid K. Sep 07 '13 at 06:26