private void button4_Click(object sender, EventArgs e) { string[] addresses = { "0x3db4B1Be10b0D39D3A0f2140aEd6Be5b79213453", "0x50D857764C66fB7E15eFafeF63a46AF4604D092C", "0x55affd5041F689a6D020545c8C97ecEFAD4f6AAe", "0x97D159383E6C66c32F89a5f08c105a52D5D5EA2C", "0x2512cCAEb46C5A62092056Da7735769A5760aBC6" }; int size = 64; int space = 32; Bitmap mainImage = new Bitmap(size * 5 + space * 4, size); using (Graphics g = Graphics.FromImage(mainImage)) { int pos = 0; foreach (var address in addresses) { var identicon = new Identicon(address, 8); g.DrawImage(identicon.GetBitmap(size), pos, 0); pos += size + space; } } saveFileDialog.Filter = "Png (*.png)|*.png"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { mainImage.Save(saveFileDialog.FileName, ImageFormat.Png); } }
/// <summary> /// Renders the requested identicon and returns it to the client. /// </summary> /// <param name="context"><see cref="HttpContext"/> with the current request and response.</param> public void ProcessRequest(HttpContext context) { if (IdenticonRequest.TryParse(context.Request.Url.Query, out var request)) { // The urls are permanent so it is ok to cache icons for a long time context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetMaxAge(TimeSpan.FromDays(30)); var icon = Identicon.FromHash(request.Hash, request.Size); icon.Style = request.Style; switch (request.Format) { case ExportImageFormat.Png: context.Response.ContentType = "image/png"; icon.SaveAsPng(context.Response.OutputStream); break; case ExportImageFormat.Svg: context.Response.ContentType = "image/svg+xml"; icon.SaveAsSvg(context.Response.OutputStream); break; default: throw new NotSupportedException($"The image format '{request.Format}' is not supported by {nameof(IdenticonHttpHandler)}."); } } else { throw new HttpException(404, "Icon not found"); } }
private void button5_Click(object sender, EventArgs e) { Identicon identicon = new Identicon(textBox1.Text.Trim(), 8); int size = Convert.ToInt32(textBox2.Text); this.Icon = identicon.GetIcon(64); }
public IActionResult Index([FromServices] IServerConfig cfg, int avatarId) { if (!Directory.Exists("data/avatars")) { Directory.CreateDirectory("data/avatars"); } var response = new MemoryStream(); if (System.IO.File.Exists("data/avatars/" + avatarId)) { response.Close(); var file = System.IO.File.ReadAllBytes("data/avatars/" + avatarId); return(File(file, "image/png")); } var icon = Identicon.FromValue( $"{avatarId}{cfg.Server.Hostname}{cfg.Server.Port}", 1024, "SHA384" ); icon.Style.BackColor = Color.Transparent; icon.SaveAsPng(response); response.Position = 0; System.IO.File.WriteAllBytes("data/avatars/" + avatarId, response.GetBuffer()); return(File(response, "image/png")); }
public void Identicon_Svg() { var icon = Identicon.FromValue("Jdenticon", 100); var expected = icon.SaveAsSvg(); AssertEqualRewinded("SaveAsSvg()", expected, icon.SaveAsSvg()); AssertEqualRewinded("SaveAsSvg(false)", expected, icon.SaveAsSvg(false)); AssertEqualStream("SaveAsSvg(stream)", expected, stream => icon.SaveAsSvg(stream)); AssertEqualWriter("SaveAsSvg(writer)", expected, writer => icon.SaveAsSvg(writer)); AssertEqualFile("SaveAsSvg(path)", expected, path => icon.SaveAsSvg(path)); AssertEqualStream("SaveAsSvg(stream, false)", expected, stream => icon.SaveAsSvg(stream, false)); AssertEqualWriter("SaveAsSvg(writer, false)", expected, writer => icon.SaveAsSvg(writer, false)); AssertEqualFile("SaveAsSvg(path, false)", expected, path => icon.SaveAsSvg(path, false)); AssertEqualStream("SaveAsSvgAsync(stream)", expected, stream => icon.SaveAsSvgAsync(stream)); AssertEqualWriter("SaveAsSvgAsync(writer)", expected, writer => icon.SaveAsSvgAsync(writer)); AssertEqualFile("SaveAsSvgAsync(path)", expected, path => icon.SaveAsSvgAsync(path)); AssertEqualStream("SaveAsSvgAsync(stream, false)", expected, stream => icon.SaveAsSvgAsync(stream, false)); AssertEqualWriter("SaveAsSvgAsync(writer, false)", expected, writer => icon.SaveAsSvgAsync(writer, false)); AssertEqualFile("SaveAsSvgAsync(path, false)", expected, path => icon.SaveAsSvgAsync(path, false)); var expectedFragment = icon.SaveAsSvg(true); AssertEqualRewinded("SaveAsSvg(true)", expectedFragment, icon.SaveAsSvg(true)); AssertEqualStream("SaveAsSvg(stream, true)", expectedFragment, stream => icon.SaveAsSvg(stream, true)); AssertEqualWriter("SaveAsSvg(writer, true)", expectedFragment, writer => icon.SaveAsSvg(writer, true)); AssertEqualFile("SaveAsSvg(path, true)", expectedFragment, path => icon.SaveAsSvg(path, true)); AssertEqualStream("SaveAsSvgAsync(stream, true)", expectedFragment, stream => icon.SaveAsSvgAsync(stream, true)); AssertEqualWriter("SaveAsSvgAsync(writer, true)", expectedFragment, writer => icon.SaveAsSvgAsync(writer, true)); AssertEqualFile("SaveAsSvgAsync(path, true)", expectedFragment, path => icon.SaveAsSvgAsync(path, true)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddLogging(); var ownerName = Environment.GetEnvironmentVariable("AGENT_NAME") ?? NameGenerator.GetRandomName(); // TODO: Allow the configuration of a AGENT_URL, and fall back to this computed version. // TODO: Fix this hack based on Jdenticon URL encoding var hash = "Ci8A" + Identicon.FromValue(ownerName, 100).Hash.ToBase64String().Replace('-', '~') + "--"; // Register agent framework dependency services and handlers services.AddAgentFramework(builder => { builder.AddBasicAgent <SimpleWebAgent>(c => { c.OwnerName = Environment.GetEnvironmentVariable("AGENT_NAME") ?? NameGenerator.GetRandomName(); c.EndpointUri = new Uri(Environment.GetEnvironmentVariable("ENDPOINT_HOST") ?? Environment.GetEnvironmentVariable("ASPNETCORE_URLS")); c.WalletConfiguration = new WalletConfiguration { Id = "WebAgentWallet" }; c.WalletCredentials = new WalletCredentials { Key = "MyWalletKey" }; c.OwnerImageUrl = c.EndpointUri + "identicons/" + hash; }); }); // Register custom handlers with DI pipeline services.AddSingleton <BasicMessageHandler>(); services.AddSingleton <TrustPingMessageHandler>(); }
private void UpdateIdenticon() { if (!string.IsNullOrEmpty(userName) && isLoaded) { identicon = new Identicon(userName, encryptionType, size, rounds, salt, quality); IdenticonCanvas.Source = Convert(identicon.GetImage()); } }
private void Render() { using (var context = visual.RenderOpen()) { var rect = new Rectangle(0, 0, (int)ActualWidth, (int)ActualHeight); Identicon.FromValue(Value, Math.Min(rect.Width, rect.Height)).Draw(context, rect); } }
public static IdenticonResult FromIcon(Identicon icon, ExportImageFormat format = ExportImageFormat.Png) { if (icon == null) { throw new ArgumentNullException(nameof(icon)); } return(new IdenticonResult(icon, format)); }
public void set_texture(string address) { Identicon icon = new Identicon(address, 8); Texture2D texture = icon.GetBitmap(16); GetComponent <Renderer>().material.mainTexture = texture; texture.Apply(); }
private void button1_Click(object sender, EventArgs e) { //size 8x8 is the standard one, used in Mist etc... Identicon identicon = new Identicon(textBox1.Text.Trim(), 8); int size = Convert.ToInt32(textBox2.Text); pictureBox1.Size = new System.Drawing.Size(size, size); pictureBox1.Image = identicon.GetBitmap(size); }
private void DrawIcon() { var bitmap = new Bitmap(64, 64); var g = Graphics.FromImage(bitmap); Identicon.FromValue(tokenID, 64).Draw(g, new Rectangle(0, 0, 64, 64)); TokenIcon.Fill = new ImageBrush(Helper.BitmapToImageSource(bitmap)); }
public string GenerateAndSaveAvatar(string username) { var icon = Identicon.FromValue(username, size: 512); var filename = GenerateFilename() + ".png"; var pathToSave = GetFullAvatarPath(filename); icon.SaveAsPng(pathToSave); return(filename); }
public ActionResult UserImage(int?size, string UserId) { if (size == null) { size = 100; } if (UserId != null) { } else { if (User.Identity.IsAuthenticated) { UserId = User.Identity.GetUserId(); } } // Check for image in DB using (var db = new ZapContext()) { MemoryStream ms = new MemoryStream(); if (db.Users.Where(u => u.AppId == UserId).Count() > 0) { var img = db.Users.Where(u => u.AppId == UserId).First().ProfileImage; if (img.Image != null) { Image png = Image.FromStream(new MemoryStream(img.Image)); Bitmap thumb = ImageExtensions.ResizeImage(png, (int)size, (int)size); byte[] data = thumb.ToByteArray(ImageFormat.Png); return(File(data, "image/png")); } } // Alternative if userId was username else if (db.Users.Where(u => u.Name == UserId).Count() > 0) { var userAppId = db.Users.Where(u => u.Name == UserId).FirstOrDefault().AppId; var img = db.Users.Where(u => u.AppId == userAppId).First().ProfileImage; if (img.Image != null) { Image png = Image.FromStream(new MemoryStream(img.Image)); Bitmap thumb = ImageExtensions.ResizeImage(png, (int)size, (int)size); byte[] data = thumb.ToByteArray(ImageFormat.Png); return(File(data, "image/png")); } } var icon = Identicon.FromValue(UserId, size: (int)size); icon.SaveAsPng(ms); return(File(ms.ToArray(), "image/png")); } }
private void button3_Click(object sender, EventArgs e) { Identicon identicon = new Identicon(textBox1.Text.Trim(), 8); int size = Convert.ToInt32(textBox2.Text); saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { identicon.GetBitmap(size).Save(saveFileDialog.FileName); Process.Start(saveFileDialog.FileName); } }
public void Identicon_Png() { var icon = Identicon.FromValue("Jdenticon", 100); var expected = icon.SaveAsPng(); AssertEqualRewinded("SaveAsPng()", expected, icon.SaveAsPng()); AssertEqualStream("SaveAsPng(stream)", expected, stream => icon.SaveAsPng(stream)); AssertEqualFile("SaveAsPng(path)", expected, path => icon.SaveAsPng(path)); AssertEqualStream("SaveAsPngAsync(stream)", expected, stream => icon.SaveAsPngAsync(stream)); AssertEqualFile("SaveAsPngAsync(path)", expected, path => icon.SaveAsPngAsync(path)); }
protected override void OnAppearing() { base.OnAppearing(); LabelUsername.Text = Application.Current.Properties["username"].ToString(); Stream stream = new MemoryStream(); stream = Identicon.FromValue(Application.Current.Properties["username"].ToString(), 150).SaveAsPng(); ImageSource avatarSource = ImageSource.FromStream(() => stream); AvatarImage.Source = avatarSource; }
/// <summary> /// Generates an URL to an identicon. /// </summary> /// <param name="helper">The <see cref="IUrlHelper"/>.</param> /// <param name="icon">The icon that will be rendered.</param> /// <param name="size">The size of the generated icon in pixels. If no size is specified the size of <paramref name="icon"/> will be used.</param> /// <param name="format">The file format of the generated icon.</param> /// <remarks> /// <para> /// This extension method can be used in views to generate urls to identicons, /// which are handled by the Jdenticon middleware. /// Insert a call to <see cref="IdenticonBuilderExtensions.UseJdenticon"/> right above /// <see cref="Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles"/> to enable the /// Jdenticon middleware. /// </para> /// <code language="cs" title="Startup.cs"> /// public class Startup /// { /// /* ... */ /// /// public void Configure(IApplicationBuilder app, IHostingEnvironment env) /// { /// /* ... */ /// app.UseJdenticon(); /*highlight*/ /// app.UseStaticFiles(); /// app.UseMvc(); /// /* ... */ /// } /// } /// </code> /// </remarks> /// <example> /// <para> /// This example shows how to use the <see cref="IUrlHelper"/> extension methods to generate /// identicon urls. /// </para> /// <code language="html" title="HtmlHelper approach"> /// @using Jdenticon.AspNetCore; /// /// <!-- The following markup --> /// /// <div class="user-info"> /// <img src="@Url.Identicon("JohnDoe64", 60)" width="60" height="60" alt="JohnDoe64 icon" > /// <div class="user-info__name">JohnDoe64</div> /// </div> /// /// <!-- is rendered as --> /// /// <div class="user-info"> /// <img src="/identicons/5AMA8Xyneag78XyneQ--" width="60" height="60" alt="JohnDoe64 icon" /> /// <div class="user-info__name">JohnDoe64</div> /// </div> /// </code> /// </example> /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> was less than 1.</exception> /// <exception cref="ArgumentNullException"><paramref name="helper"/> or <paramref name="icon"/> was <c>null</c>.</exception> 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)); }
public static string GenerateIcon(string username) { var tmpdir = Path.GetTempPath(); var appFolder = Path.Combine(tmpdir, AppConstants.AppName); Directory.CreateDirectory(appFolder); var imgFile = Path.Combine(appFolder, username + ".png"); if (File.Exists(imgFile) == false) { Identicon.FromValue(username, 160).SaveAsPng(imgFile); } return(imgFile); }
public void Identicon_Emf() { var icon = Identicon.FromValue("Jdenticon", 100); // Dry run since the first file seems to be a little different icon.SaveAsEmf(); var expected = icon.SaveAsEmf(); AssertEqualRewinded("SaveAsEmf()", expected, icon.SaveAsEmf()); AssertEqualStream("SaveAsEmf(stream)", expected, stream => icon.SaveAsEmf(stream)); AssertEqualFile("SaveAsEmf(path)", expected, path => icon.SaveAsEmf(path)); AssertEqualStream("SaveAsEmfAsync(stream)", expected, stream => icon.SaveAsEmfAsync(stream)); AssertEqualFile("SaveAsEmfAsync(path)", expected, path => icon.SaveAsEmfAsync(path)); }
public static void InitAreaCompleteInfoForEverest() { if (Everest.Flags.IsDisabled) { return; } if (Settings.Instance.SpeedrunClock > SpeedrunType.Off) { versionFull = $"{Celeste.Instance.Version}\n{Everest.Build}"; using (Stream stream = Identicon.FromHash(Everest.InstallationHash, 100).SaveAsPng()) identicon = Texture2D.FromStream(Celeste.Instance.GraphicsDevice, stream); } }
public Bitmap GetIdenticon(int size) { Color fillColor; byte r = byte.Parse(Revision.Diff.HashOfDiff.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier); byte g = byte.Parse(Revision.Diff.HashOfDiff.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier); byte b = byte.Parse(Revision.Diff.HashOfDiff.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier); fillColor = Color.FromArgb(r, g, b); var identicon = Identicon.FromValue(Revision.Diff.HashOfDiff, size); identicon.Style = new IdenticonStyle(); identicon.Style.BackColor = Jdenticon.Rendering.Color.FromArgb(255, fillColor.R, fillColor.G, fillColor.B); return(identicon.ToBitmap()); }
private void button2_Click(object sender, EventArgs e) { Identicon identicon = new Identicon(textBox1.Text.Trim(), 8); int size = Convert.ToInt32(textBox2.Text); saveFileDialog.Filter = "Icon (*.ico)|*.ico"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create)) { identicon.GetIcon(size).Save(fs); fs.Close(); fs.Dispose(); } Process.Start(saveFileDialog.FileName); } }
private void CreateBlocky(int resolution = 64) { Identicon id = new Identicon(accountAddress, 8); List <Identicon.PixelData> pixels = id.GetIdenticonPixels(resolution); Texture2D texture = new Texture2D(resolution, resolution); for (int i = 0; i < pixels.Count; ++i) { Color col = new Color(pixels[i].RGB[0] / 255f, pixels[i].RGB[1] / 255f, pixels[i].RGB[2] / 255f); texture.SetPixel(pixels[i].x, resolution - pixels[i].y - 1, col); } texture.Apply(); identiconImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero); }
static void Main(string[] args) { var icon = Identicon.FromValue("df", 160); icon.Style.BackColor = Jdenticon.Rendering.Color.Transparent; icon.SaveAsPng("M:\\test1509-own.png"); using (var bmp = icon.ToBitmap()) { bmp.Save("M:\\test1509-gdi.png", System.Drawing.Imaging.ImageFormat.Png); } //return; Benchmarker.Run("Own", () => { using (var stream = new MemoryStream()) { icon.SaveAsPng(stream); } }, 200); Benchmarker.Run("Gdi", () => { using (var stream = new MemoryStream()) { icon.ToBitmap().Save(stream, System.Drawing.Imaging.ImageFormat.Png); } }, 200); Benchmarker.Run("Own", () => { using (var stream = new MemoryStream()) { icon.SaveAsPng(stream); } }, 200); Benchmarker.Run("Gdi", () => { using (var stream = new MemoryStream()) { icon.ToBitmap().Save(stream, System.Drawing.Imaging.ImageFormat.Png); } }, 200); }
public void CreateIdenticon(string identifier) { //these are fine tuned. Fabric should be not too light, as there is quite a bit of white space in the design //identicon var identiconId = identifier; var identiconStyle = new IdenticonStyle { ColorLightness = Range.Create(0.22f, 0.75f), GrayscaleLightness = Range.Create(0.52f, 0.7f), GrayscaleSaturation = 0.10f, ColorSaturation = 0.75f, Padding = 0f }; var identicon = Identicon.FromValue(identiconId, size: 80); identicon.Style = identiconStyle; if (!File.Exists(IdenticonImagePath())) { identicon.SaveAsPng(IdenticonImagePath()); } //fabric var fabricId = ReverseString(identifier); var fabricStyle = new IdenticonStyle { ColorLightness = Range.Create(0.33f, 0.48f), GrayscaleLightness = Range.Create(0.30f, 0.45f), ColorSaturation = 0.7f, GrayscaleSaturation = 0.7f, Padding = 0f }; var fabricIcon = Identicon.FromValue(fabricId, size: 13); fabricIcon.Style = fabricStyle; if (!File.Exists(FabricImagePath())) { fabricIcon.SaveAsPng(FabricImagePath()); } }
private static void Test(int iconNumber, IdenticonStyle style) { var icon = Identicon.FromValue(iconNumber, 50); if (style != null) { icon.Style = style; } using (var actualStream = new MemoryStream()) { icon.SaveAsPng(actualStream); var actualBytes = actualStream.ToArray(); using (var expectedStream = GetExpectedIcon($"{iconNumber}.png")) { // +1 to be able to detect a too short actual icon var expectedBytes = new byte[actualBytes.Length + 1]; var expectedByteCount = expectedStream.Read(expectedBytes, 0, actualBytes.Length); if (expectedByteCount != actualBytes.Length || expectedBytes.Take(expectedByteCount).SequenceEqual(actualBytes) == false) { Assert.Fail("Icon '{0}' failed PNG rendering test.", iconNumber); } } } var actualSvg = icon.ToSvg(); using (var expectedStream = GetExpectedIcon($"{iconNumber}.svg")) { using (var reader = new StreamReader(expectedStream)) { var expectedSvg = reader.ReadToEnd(); if (actualSvg != expectedSvg) { Assert.Fail("Icon '{0}' failed SVG rendering test.", iconNumber); } } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string information) { var data = information.ToLower().Replace(" ", ""); var imgFile = Path.Combine(Path.GetTempPath(), data + ".png"); if (File.Exists(imgFile)) { return(imgFile); } else { Identicon.FromValue(data, size: 160) .SaveAsPng(imgFile); return(imgFile); } } return(string.Empty); }
private async Task HandleRequestAsync(HttpContext context, IdenticonRequest request) { var icon = Identicon.FromHash(request.Hash, request.Size); icon.Style = request.Style; var headers = context.Response.GetTypedHeaders(); Stream data; string contentType; switch (request.Format) { case ExportImageFormat.Svg: data = icon.SaveAsSvg(); contentType = "image/svg+xml"; break; default: data = icon.SaveAsPng(); contentType = "image/png"; break; } try { context.Response.ContentType = contentType; context.Response.ContentLength = data.Length; // The urls are permanent so it is ok to cache icons for a long time headers.CacheControl = new CacheControlHeaderValue { Public = true, MaxAge = TimeSpan.FromDays(30) }; await data.CopyToAsync(context.Response.Body); } finally { data?.Dispose(); } }
public void LoadJdenticon(string address) { Identicon icon = Identicon.FromValue(address, 100); Identicon.DefaultStyle.BackColor = Jdenticon.Rendering.Color.Transparent; icon.SaveAsPng(Application.persistentDataPath + "/icon.png"); Texture2D tex = null; byte[] fileData; if (File.Exists(Application.persistentDataPath + "/icon.png")) { fileData = File.ReadAllBytes(Application.persistentDataPath + "/icon.png"); tex = new Texture2D(2, 2); tex.LoadImage(fileData); } Icon.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)); Address.text = address; }