Пример #1
0
 private IdenticonResult(Identicon icon, ExportImageFormat format = ExportImageFormat.Png)
 {
     this.icon   = icon;
     this.format = format;
 }
Пример #2
0
 /// <summary>
 /// Creates an <see cref="IdenticonResult"/> instance with the specified hash.
 /// </summary>
 /// <param name="hash">The hex encoded hash that will be used as base for the icon. The hash string must contain at least 12 characters.</param>
 /// <param name="size">The size of the icon in pixels.</param>
 /// <param name="format">The format of the generated icon.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> was less than 1.</exception>
 /// <exception cref="ArgumentException"><paramref name="hash"/> was too short.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="hash"/> was <c>null</c>.</exception>
 public static IdenticonResult FromHash(string hash, int size, ExportImageFormat format = ExportImageFormat.Png)
 {
     return(new IdenticonResult(Identicon.FromHash(hash, size), format));
 }
Пример #3
0
 /// <summary>
 /// Creates an <see cref="IdenticonResult"/> instance with a hash of the specified object.
 /// </summary>
 /// <param name="value">The string representation of this object will be hashed and used as base for this icon. Null values are supported and handled as empty strings.</param>
 /// <param name="size">The size of the icon in pixels.</param>
 /// <param name="format">The format of the generated icon.</param>
 /// <param name="hashAlgorithmName">The name of the hash algorithm to use for hashing.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> was less than 1.</exception>
 public static IdenticonResult FromValue(object value, int size, ExportImageFormat format = ExportImageFormat.Png, string hashAlgorithmName = "SHA1")
 {
     return(new IdenticonResult(Identicon.FromValue(value, size, hashAlgorithmName), format));
 }
Пример #4
0
 /// <summary>
 /// Creates an <see cref="IdenticonResult"/> instance with a hash of the specified object.
 /// </summary>
 /// <param name="icon">The <see cref="Identicon"/> to be rendered.</param>
 /// <param name="format">The format of the generated icon.</param>
 /// <exception cref="ArgumentNullException"><paramref name="icon"/> was <c>null</c>.</exception>
 public static IdenticonResult FromIcon(Identicon icon, ExportImageFormat format = ExportImageFormat.Png)
 {
     return(new IdenticonResult(icon, format));
 }
Пример #5
0
        public static string Identicon(this IUrlHelper helper, byte[] hash, int size, ExportImageFormat format = ExportImageFormat.Png, IdenticonStyle?style = null)
        {
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }
            if (hash.Length < 6)
            {
                throw new ArgumentException("The specified hash is too short. At least 6 bytes are required.", nameof(hash));
            }
            if (size < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(size), size, "The size should be 1 pixel or larger");
            }

            return(IdenticonUrl.Create(helper.ActionContext.HttpContext, hash, size, format, style));
        }
Пример #6
0
        public static string Identicon(this IUrlHelper helper, object?value, int size, ExportImageFormat format = ExportImageFormat.Png, IdenticonStyle?style = null)
        {
            var hash = HashGenerator.ComputeHash(value, "SHA1");

            return(helper.Identicon(hash, size, format, style));
        }
Пример #7
0
        public static string Identicon(this IUrlHelper helper, Identicon icon, int size = 0, ExportImageFormat format = ExportImageFormat.Png)
        {
            if (icon == null)
            {
                throw new ArgumentNullException(nameof(icon));
            }
            if (size == 0)
            {
                size = icon.Size;
            }

            return(helper.Identicon(icon.Hash, size, format, icon.Style));
        }
Пример #8
0
 /// <summary>
 /// Export PDF as images with default size with the required image format.
 /// </summary>
 /// <param name="imageFormat">Image format</param>
 /// <param name="directory">Output directory</param>
 internal void ExportAsImage(ExportImageFormat imageFormat, string directory)
 {
     BitmapSource[] images = pdfViewerControl.ExportAsImage(0, pdfViewerControl.PageCount - 1);
     SaveImages(images, imageFormat, directory, "Images");
 }