/// <summary> /// Gets the fingerprint image from the specified <see cref="ResourceRepository"/>. /// </summary> /// <param name="fingerprint">The fingerprint which image is being retrieved.</param> /// <param name="repository">The object used to store and retrieve resources.</param> /// <returns>The retrieved fingerprint image.</returns> public Bitmap GetResource(string fingerprint, ResourceRepository repository) { byte[] rawImage = null; foreach (string ext in new[] { "tif", "bmp", "jpg" }) { string resourceName = string.Format("{0}.{1}", fingerprint, ext); rawImage = repository.RetrieveResource(resourceName); if (rawImage != null) { break; } } if (rawImage == null) { return(null); } Bitmap srcBitmap = Image.FromStream(new MemoryStream(rawImage)) as Bitmap; if (srcBitmap == null) { return(null); } Bitmap returnBitmap; using (srcBitmap) { PixelFormat pixelFormat; switch (srcBitmap.PixelFormat) { case PixelFormat.Format8bppIndexed: case PixelFormat.Indexed: case PixelFormat.Format4bppIndexed: case PixelFormat.Format1bppIndexed: pixelFormat = PixelFormat.Format24bppRgb; break; default: pixelFormat = srcBitmap.PixelFormat; break; } returnBitmap = new Bitmap(srcBitmap.Width, srcBitmap.Height, pixelFormat); returnBitmap.SetResolution(srcBitmap.HorizontalResolution, srcBitmap.VerticalResolution); Graphics g = Graphics.FromImage(returnBitmap); g.DrawImage(srcBitmap, 0, 0); } return(returnBitmap); }
/// <summary> /// Gets minutia list from the specified fingerprint and <see cref="ResourceRepository"/>. /// </summary> /// <param name="fingerprint">The fingerprint which minutia list is being retrieved.</param> /// <param name="repository">The object used to store and retrieve resources.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when the fingerprint is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the minutia list extractor is not assigned.</exception> /// <returns>The retrieved minutia list.</returns> public List <Minutia> GetResource(string fingerprint, ResourceRepository repository) { bool isPersistent = IsResourcePersistent(); string resourceName = string.Format("{0}.{1}", fingerprint, GetSignature()); if (isPersistent && repository.ResourceExists(resourceName)) { return(MinutiaListSerializer.FromByteArray(repository.RetrieveResource(resourceName))); } List <Minutia> resource = Extract(fingerprint, repository); if (resource == null) { return(null); } if (isPersistent) { repository.StoreResource(resourceName, MinutiaListSerializer.ToByteArray(resource)); } return(resource); }