private IdenticonGenerator CreateGenString(string alg, string s, bool useextended, bool usestatic) { var g = new IdenticonGenerator(alg); if (usestatic) g.DefaultBrushGenerator = new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(s)); if (useextended) g.DefaultBlockGenerators = IdenticonGenerator.ExtendedBlockGeneratorsConfig; return g; }
private IdenticonGenerator CreateGenIp(string alg, IPAddress ip, bool useextended, bool usestatic) { var g = new IdenticonGenerator(alg); if (usestatic) g.DefaultBrushGenerator = new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromIPAddress(ip)); if (useextended) g.DefaultBlockGenerators = IdenticonGenerator.ExtendedBlockGeneratorsConfig; return g; }
public ActionResult Index(int dimension, string text) { text = text ?? HttpContext.Request.UserHostAddress; var ic = new IdenticonGenerator(); ic.DefaultBrushGenerator = new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(text)); var bitmap = ic.Create(text, new Size(dimension, dimension)); var ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); return(File(ms.ToArray(), "image/png")); }
private void CreateButton_Click(object sender, EventArgs e) { try { var bg = ColorGenBox.Text.Equals("Random") ? (IBrushGenerator) new RandomColorBrushGenerator() : new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(ValueBox.Text)); ResultBox.Image = new IdenticonGenerator(AlgorithmBox.Text) .WithSize((int)WidthBox.Value, (int)HeightBox.Value) .WithBackgroundColor(BackgroundColorBox.BackColor) .WithBlocks((int)HorizontalBox.Value, (int)VerticalBox.Value) .WithBlockGenerators(IdenticonGenerator.ExtendedBlockGeneratorsConfig) .WithBrushGenerator(bg) .Create(ValueBox.Text); } catch (Exception ex) { MessageBox.Show(string.Format("Error: {0}", ex.Message), "Uh oh!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static IHtmlString GenerateIdenticon(this HtmlHelper html, string value, int dimension, bool useStaticBrush = false) { var i = new IdenticonGenerator() .WithBlockGenerators(IdenticonGenerator.ExtendedBlockGeneratorsConfig) .WithBrushGenerator(useStaticBrush ? (IBrushGenerator) new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(value)) : new RandomColorBrushGenerator() ) .WithSize(dimension, dimension); using (var bitmap = i.Create(value)) using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Png); var img = new TagBuilder("img"); img.Attributes.Add("width", bitmap.Width.ToString()); img.Attributes.Add("height", bitmap.Height.ToString()); img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(stream.ToArray()))); return(MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing))); } }
public Bitmap GenerateIcon(string algorithmBox) { var randomValue = RandomStr(); var bg = _colorGenBox.Equals("Random") ? (IBrushGenerator) new RandomColorBrushGenerator() : new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(randomValue)); var result = new IdenticonGenerator(algorithmBox) .WithSize(400, 400) .WithBackgroundColor(Color.Black) .WithBlocks(5, 5) .WithBlockGenerators(IdenticonGenerator.ExtendedBlockGeneratorsConfig) .WithBrushGenerator(bg) .Create(randomValue); return(result); }
public Bitmap GenerateIcon() { var randomValue = RandomStr(); var bg = _colorGenBox.Equals("Random") ? (IBrushGenerator) new RandomColorBrushGenerator() : new StaticColorBrushGenerator(StaticColorBrushGenerator.ColorFromText(randomValue)); var result = new IdenticonGenerator(MD5) .WithSize(250, 250) .WithBackgroundColor(Color.Black) .WithBlocks(5, 5) .WithBlockGenerators(IdenticonGenerator.DefaultBlockGeneratorsConfig) .WithBrushGenerator(bg) .Create(randomValue); return(result); }