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.

9
  • possible duplicate of .NET String to byte Array C# Commented Sep 7, 2013 at 4:54
  • Also: stackoverflow.com/q/14360257/109702, stackoverflow.com/q/11730373/109702, Commented Sep 7, 2013 at 4:56
  • "I have converted the fingerprint data to a text format" - What type was the fingerprint data to begin with? a byte array? Commented Sep 7, 2013 at 4:57
  • No they dont provide a simple byte array. They want users to play with their TYPES only. Commented Sep 7, 2013 at 5: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. Commented Sep 7, 2013 at 5:12

4 Answers 4

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;.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried what you told me to do. But it still gives me the same exception. Parameter is not Valid.
I am not sure abut that..Because textFIR is an object which encodes actual finger print data (NBioAPI.Type.HFIR) into a text.
I just went through their documentation (nitgen.com.br/download/…). 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.
Any idea on this dotNET? I am stuck on this since last week. I would really appreciate your help.
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.
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.

6 Comments

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?
If it is a COM component then regsvr32 NImgConv.dll and add ref from COM tab in VS otherwise follow the instructions stackoverflow.com/questions/569603/…
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.
It might not be a COM component; try following the instructions from the url stackoverflow.com/questions/569603/…
I am sorry but I dont even have an option for creating C++/CLI projects in my VS. I am totally new to this.
|
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.

1 Comment

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.
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);
    }

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.