/// <summary> /// Reads the photo. /// </summary> /// <returns></returns> public Image ReadPhoto() { if (reader == null) { return(null); } EIDPicture photo = new EIDPicture(); MemoryStream ms = null; if (NativeMethods.ReadPhotoEx(reader.Index, photo)) { if (photo.pictureLength == 0) { return(null); } ms = new MemoryStream(photo.picture); Image result = Image.FromStream(ms); ms.Dispose(); return(result); } else { return(null); } }
/// <summary> /// Encodes the photo. /// </summary> /// <returns></returns> public byte[] EncodePhoto() { if (reader == null) { return(null); } EIDPicture photo = new EIDPicture(); if (NativeMethods.ReadPhotoEx(reader.Index, photo)) { if (photo.pictureLength == 0) { return(null); } int len = NativeMethods.GetEncodedPhotoSize(photo); byte[] buffer = new byte[len]; int encodedLen = NativeMethods.EncodePhoto(photo, buffer, len); encodedLen--; if (encodedLen > len) { return(null); } if (encodedLen == len) { return(buffer); } byte[] result = new byte[encodedLen]; Array.Copy(buffer, result, encodedLen); return(result); } else { return(null); } }
/// <summary>Encodes the photo.</summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public byte[] EncodePhoto(string fileName) { EIDPicture photo = new EIDPicture(); NativeMethods.LoadPhoto(photo, fileName); if (photo.pictureLength == 0) { return(null); } if (photo.pictureLength > 0) { int len = NativeMethods.GetEncodedPhotoSize(photo); byte[] buffer = new byte[len]; int encodedLen = NativeMethods.EncodePhoto(photo, buffer, len); encodedLen--; if (encodedLen > len) { return(null); } if (encodedLen == len) { return(buffer); } byte[] result = new byte[encodedLen]; Array.Copy(buffer, result, encodedLen); return(result); } else { return(null); } }