我怎样才能得到XML FID Digitalpersona

时间:2019-07-11 22:47:55

标签: c# xamarin

我有一个Xamarin形式的应用程序,该应用程序使用了我从Android java的这段代码成功改编的数字角色

问题是此应用仅返回指纹的byte []数组,因此我需要将fid xml发送到Web服务,以便可以比较验证手指 但我不知道如何

这是我用来解析从数字角色到数组字节的流的类

public class UruImage
{

    private static int IMAGE_HEIGHT = 290;
    private static int IMAGE_WIDTH = 384;
    private static int QUALITY = 75;
    private static string LOG_TAG = "U.are.U-Image ";

    // Raw data
    private short unknown_00;
    private byte[] unknown_07 = new byte[9];
    private byte[] unknown_2E = new byte[18];

    public short num_lines;
    public short width;
    public sbyte key_number;
    public byte[] flags_num_lines = new byte[30];
    public byte[] data;

    // setter & getter

    public void createFromData(ByteBuffer sData) //throws IOException
    {
        try
        {
            //tengo duda con lo indices en codigo java esta sData.GetShort(); sin index
            sData.Order(ByteOrder.LittleEndian);

            unknown_00 = sData.Short;
            System.Console.WriteLine(LOG_TAG+" unknown_00: " + Convert.ToString(unknown_00));

            width = sData.Short;
            System.Console.WriteLine(LOG_TAG+ "width: " + Convert.ToString(width));

            num_lines = sData.Short;
            System.Console.WriteLine(LOG_TAG+ "num_lines: " + Convert.ToString(num_lines));

            key_number = sData.Get();
            System.Console.WriteLine(LOG_TAG+ "key_number: " + Convert.ToString(key_number));

            sData.Get(unknown_07, 0, 9);
            System.Console.WriteLine(LOG_TAG+ "unknown_07: " + bytesToHex(unknown_07));

            sData.Get(flags_num_lines, 0, 30);
            System.Console.WriteLine(LOG_TAG, "flags_num_lines: " + bytesToHex(flags_num_lines));

            sData.Get(unknown_2E, 0, 18);
            System.Console.WriteLine(LOG_TAG+ "unknown_2E: " + bytesToHex(unknown_2E));

            data = new byte[(num_lines + 1) * width]; // extra line for decoding
            sData.Get(data, 0, num_lines * width);
        }
        catch (Exception ex) {
            System.Console.WriteLine(" createFromData " + ex.Message + " " + ex.ToString());
            throw new  Java.IO.IOException();
        }


    }

    public Byte[] getImageBitmap()
    {
        try
        {
            int dataOffset = 0;

            int[] pixels = new int[IMAGE_WIDTH * IMAGE_HEIGHT];
            int i = 0;
            for (int y = 0; y < IMAGE_HEIGHT; y++)
            {
                for (int x = 0; x < IMAGE_WIDTH; x++)
                {
                    int gray = data[dataOffset + i] & 0xff;
                    pixels[i] = unchecked((int)0xff000000) | gray << 16 | (gray << 8) | gray;
                    i++;
                }
            }

            Bitmap bm = Bitmap.CreateBitmap(pixels, IMAGE_WIDTH, IMAGE_HEIGHT, Bitmap.Config.Argb8888);
            MemoryStream bs = new MemoryStream();
            bm.Compress(Bitmap.CompressFormat.Jpeg, QUALITY, bs);
            return bs.ToArray();
        }
        catch (System.Exception ex) {
            System.Console.WriteLine("Get Image bitmap" + ex.Message + " " + ex.StackTrace);
        }
        return new MemoryStream().ToArray();
    }

    public byte[] getPgm()
    {
        return data;
    }

    public void invert()
    {
        try
        {
            int length = width * num_lines;
            int i;
            //duda con conversion de valor byte max_value = 0xFFFFFFFF;
            byte max_value = unchecked((byte)0xFFFFFFFF);
            for (i = 0; i < length; i++)
            {
                data[i] = (byte)(max_value - data[i]);
            }
        }
        catch (System.Exception ex) {
            System.Console.WriteLine("Invert "+ex.Message);
        }
    }


    protected static char[] hexArray = "0123456789ABCDEF".ToCharArray();
    private static String bytesToHex(byte[] bytes)
    {
        char[] hexChars = new char[bytes.Length * 2];
        for (int j = 0; j < bytes.Length; j++)
        {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[(uint)v >> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

}

0 个答案:

没有答案