/// <summary> /// Performs a Blur effect using a Gaussian distribution from the ImageProcessor library. /// </summary> /// <param name="image">The image with which to apply the effect.</param> /// <param name="size">The size of the kernel used to perform the blur.</param> /// <returns>A new image with the Blur effect applied.</returns> public Image GaussianBlur(Image image, int size) { using var factory = new ImageFactory(); factory.Load(image); factory.GaussianBlur(size); var result = factory.Image; return(new Bitmap(result)); }
public override void ProcessImage(ref ImageFactory imageFactory) { imageFactory.Resize(new Size(512, 512)); imageFactory.Saturation(-100); imageFactory.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Polaroid); imageFactory.GaussianBlur(15); imageFactory.Vignette(); imageFactory.RoundedCorners(30); imageFactory.Rotate(-5); channel.SendMessage("My old friend..."); }
public void imgFactoryFiltri() { imgf.Load(resizeImage((Bitmap)Properties.Resources.ResourceManager.GetObject(slika), new Size(400, 400))); for (int i = 0; i < filtri; ++i) { if (i % 3 == 0) { imgf.GaussianBlur(25); } else if (i % 3 == 1) { imgf.Pixelate(25); } else { imgf.Brightness(-25); } } pnlSlika.BackgroundImage = imgf.Image; }
private void BlurUnderCurtain() { BlurringAreaOnScreenLeft = 1920 * (ParentForm.Left + GroundPanel.Left + 50) / Screen.PrimaryScreen.Bounds.Width; BlurringAreaInScreenTop = 1080 * (ParentForm.Top + GroundPanel.Top) / Screen.PrimaryScreen.Bounds.Height; BlurringAreaOnScreenWidth = 1920 * 300 / Screen.PrimaryScreen.Bounds.Width; BlurringAreaOnScreenHeight = 1080 * GroundPanel.Height / Screen.PrimaryScreen.Bounds.Height; Bitmap UnderCurtainArea = new Bitmap(BlurringAreaOnScreenWidth, BlurringAreaOnScreenHeight); Graphics ScreenCopyer = Graphics.FromImage(UnderCurtainArea as Image); ScreenCopyer.CopyFromScreen(BlurringAreaOnScreenLeft, BlurringAreaInScreenTop, 0, 0, UnderCurtainArea.Size); ImageFactory imageFactory = new ImageFactory(); imageFactory.Load(UnderCurtainArea); imageFactory.Brightness(-50); imageFactory.GaussianBlur(12); BackgroundPictureBox.Image = imageFactory.Image; ScreenCopyer.Dispose(); }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _http = _client.GetService <HttpService>(); manager.CreateCommands("image", group => { group.CreateCommand("caption") .Parameter("uri", ParameterType.Required) .Parameter("parameters", ParameterType.Unparsed) .Description("Adds text to an Image.\n<`uri`> ⦗`color`⦘ ⦗`alpha`⦘ ⦗`position`⦘ ⦗`fontsize`⦘ ⦗`dropshadow`⦘\nExample usage:\n⦗`cap http://myimage.png red 0.5 center arial 12 1 hello world`⦘\n⦗`cap http://myimage.png hello world`⦘") .Alias("cap") .Do(async e => { if (e.Args.Any()) { var args = getArgs(e); string uri = e.Args[0]; if (args.Any()) { if (await isImage(uri)) { string file = "img_cap_tmp" + Guid.NewGuid().ToString() + await getImageExtension(uri); try { await DownloadImage(uri, file); } catch (WebException ex) { await _client.ReplyError(e, ex.Message); _client.Log.Error("captions", ex); if (File.Exists(file)) { File.Delete(file); } return; } if (File.Exists(file)) { byte[] pb = File.ReadAllBytes(file); var asd = new TextLayer(); asd.Text = args?["text"]; asd.FontColor = args.ContainsKey("color") ? System.Drawing.Color.FromName(args["color"]) : System.Drawing.Color.White; asd.FontFamily = args.ContainsKey("font") ? FontFamily.Families.Where(x => x.Name == args["font"]).FirstOrDefault() : FontFamily.GenericSerif; asd.DropShadow = args.ContainsKey("dropshadow") ? bool.Parse(args["dropshadow"]) : false; // asd.Position = Point.Empty; asd.Opacity = args.ContainsKey("opacity") ? int.Parse(args["opacity"]) : 100; asd.Style = args.ContainsKey("style") ? (FontStyle)Enum.Parse(typeof(FontStyle), args["style"], true) : FontStyle.Regular; asd.FontSize = args.ContainsKey("size") ? int.Parse(args["size"]) : 20; ISupportedImageFormat format = new PngFormat { Quality = 100 }; using (MemoryStream ins = new MemoryStream(pb)) using (MemoryStream outs = new MemoryStream()) using (ImageFactory iff = new ImageFactory(true)) { iff.Load(ins) .Watermark(asd) .Format(format) .Save(outs); await e.Channel.SendFile("output.png", outs); } File.Delete(file); } else { await _client.ReplyError(e, "Couldn't find your image on my end. Bug @Techbot about it."); return; } } else { await _client.ReplyError(e, "That doesn't seem to be an image..."); } } else { await _client.ReplyError(e, "No Parameters provided, aborting..."); return; } } else { await _client.Reply(e, "Usage: `cap [link] <text>`"); } }); group.CreateCommand("edit") .Parameter("uri", ParameterType.Required) .Parameter("parameters", ParameterType.Unparsed) .Description("transforms an image.\nSupported Parameters:\n\n\nTint: `tint=red`\nCensor: `censor=x;y;w;h`\n`Scaling: `w=num or h=num`\n`blur=num`\n`rot=num`\n`filp=true/false`\n`crop=true + (top=num or bottom=num or left=num or right=num)`") .Alias("e") .Do(async e => { if (e.Args.Any()) { var args = getArgs(e); string uri = e.Args[0]; if (await isImage(uri)) { string file = "img_e_tmp" + Guid.NewGuid().ToString() + await getImageExtension(uri); try { await DownloadImage(uri, file); } catch (WebException ex) { await _client.ReplyError(e, ex.Message); _client.Log.Error("captions", ex); if (File.Exists(file)) { File.Delete(file); } return; } if (File.Exists(file)) { byte[] pb = File.ReadAllBytes(file); ISupportedImageFormat format = new PngFormat { Quality = 100 }; using (MemoryStream ins = new MemoryStream(pb)) using (MemoryStream outs = new MemoryStream()) using (ImageFactory iff = new ImageFactory(true)) { iff.Load(ins); if (args.ContainsKey("rot")) { iff.Rotate(int.Parse(args["rot"])); } if (args.ContainsKey("flip")) { iff.Flip(bool.Parse(args["flip"])); } if (args.ContainsKey("blur")) { iff.GaussianBlur(int.Parse(args["blur"])); } if (args.ContainsKey("ecrop")) { iff.EntropyCrop(byte.Parse(args["ecrop"])); } if (args.ContainsKey("pixelate")) { iff.Pixelate(int.Parse(args["pixelate"])); } if (args.ContainsKey("tint")) { iff.Tint(System.Drawing.Color.FromName(args["tint"])); } if (args.ContainsKey("replacecolor")) { string[] rcargs = args["replacecolor"].Split(';'); System.Drawing.Color tar = System.Drawing.Color.FromName(rcargs[0]); System.Drawing.Color rep = System.Drawing.Color.FromName(rcargs[1]); if (rcargs.Length > 2 && int.Parse(rcargs[2]) >= 128 || int.Parse(rcargs[2]) < 0) { await _client.ReplyError(e, "Fuzzines mix and max values are 0 - 128"); File.Delete(file); return; } int fuzz = rcargs.Length > 2 ? int.Parse(rcargs[2]) : 128; iff.ReplaceColor(tar, rep, fuzz); } if (args.ContainsKey("censor")) { string[] cargs = args["censor"].Split(';'); var pixels = int.Parse(cargs[4]); var x = int.Parse(cargs[0]); var y = -int.Parse(cargs[1]); var w = int.Parse(cargs[2]); var h = int.Parse(cargs[3]); iff.Pixelate(pixels, new Rectangle(new Point(x, y), new Size(w, h))); } if (args.ContainsKey("w") || args.ContainsKey("h")) { int width = 0, height = 0; if (args.ContainsKey("w")) { width = int.Parse(args["w"]); } if (args.ContainsKey("h")) { height = int.Parse(args["h"]); } iff.Resize(new ResizeLayer(new Size(width, height), ResizeMode.Stretch, AnchorPosition.Center, true, null, new Size(5000, 5000))); } if (args.ContainsKey("crop")) { int top = 0, bottom = 0, left = 0, right = 0; // is there a better way to do this? if (args.ContainsKey("top")) { top = int.Parse(args["top"]); } if (args.ContainsKey("bottom")) { bottom = int.Parse(args["bottom"]); } if (args.ContainsKey("left")) { left = int.Parse(args["left"]); } if (args.ContainsKey("right")) { right = int.Parse(args["right"]); } iff.Crop(new CropLayer( top, bottom, left, right, CropMode.Percentage)); } iff .Format(format) .Save(outs); await e.Channel.SendFile("output.png", outs); } File.Delete(file); } else { await _client.ReplyError(e, "Couldn't find your image on my end. Bug @Techbot about it."); return; } } else { await _client.ReplyError(e, "That doesn't seem to be an image..."); } } }); }); }
private void blurToolStripMenuItem1_Click(object sender, EventArgs e) { imageFactory.GaussianBlur(10); pictureBox.Image = imageFactory.Image; }
public IImageTransformer GaussianBlur(int size) { _image.GaussianBlur(size); return(this); }
public override void Apply(ImageFactory fs) { fs = fs.GaussianBlur(new GaussianLayer(size, sigma, threshold)); }
private void goGenerateProcessesFriendship() { int artOfficial = Process.GetProcesses().Length; /* Previous code for tallying after we get the processes...which is just a waste of time. Still, it's here. * foreach (var theProcess in Process.GetProcesses()) * { * if (theProcess.MainWindowTitle != "" && theProcess.MainWindowTitle != "Space") * { * artOfficial++; * } * }*/ if (artOfficial != currentCountProc) { spaceForProcesses.Controls.Clear(); int procCount = 0; foreach (var theProcess in Process.GetProcesses()) { if (procCount != 0 && procCount != 4) { if ((theProcess.MainWindowTitle != "" && theProcess.Modules[0].FileName != "ProjectSnowshoes.exe") && theProcess.MainWindowHandle != null) { foreach (var h in getHandles(theProcess)) { if (IsWindowVisible(h)) { PictureBox hmGreatJobFantasticAmazing = new PictureBox(); StringBuilder sb = new StringBuilder(GetWindowTextLength(h) + 1); GetWindowText(h, sb, sb.Capacity); hmGreatJobFantasticAmazing.Margin = new Padding(6, 0, 6, 0); hmGreatJobFantasticAmazing.Visible = true; hmGreatJobFantasticAmazing.SizeMode = PictureBoxSizeMode.CenterImage; hmGreatJobFantasticAmazing.BackgroundImageLayout = ImageLayout.Zoom; Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap().Save(@"C:\ProjectSnowshoes\temptaskico.png"); ImageFactory grayify = new ImageFactory(); grayify.Load(@"C:\ProjectSnowshoes\temptaskico.png"); Size sizeeeee = new System.Drawing.Size(); sizeeeee.Height = 20; sizeeeee.Width = 20; ImageProcessor.Imaging.ResizeLayer reLay = new ImageProcessor.Imaging.ResizeLayer(sizeeeee); grayify.Resize(reLay); hmGreatJobFantasticAmazing.Image = grayify.Image; hmGreatJobFantasticAmazing.Click += (sender, args) => { ShowWindow(theProcess.MainWindowHandle, 5); ShowWindow(theProcess.MainWindowHandle, 9); }; hmGreatJobFantasticAmazing.MouseHover += (sender, args) => { Properties.Settings.Default.stayHere = true; Properties.Settings.Default.Save(); int recordNao = hmGreatJobFantasticAmazing.Left; hmGreatJobFantasticAmazing.Image.Save(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); Size sizeeeeeA = new System.Drawing.Size(); sizeeeeeA.Height = 100; sizeeeeeA.Width = 100; ImageProcessor.Imaging.ResizeLayer reLayA = new ImageProcessor.Imaging.ResizeLayer(sizeeeeeA); ImageProcessor.Imaging.GaussianLayer gauLay = new ImageProcessor.Imaging.GaussianLayer(); gauLay.Sigma = 2; gauLay.Threshold = 10; gauLay.Size = 20; ImageFactory backify = new ImageFactory(); backify.Load(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); backify.Brightness(-30); backify.Resize(reLayA); backify.GaussianBlur(gauLay); ImageProcessor.Imaging.CropLayer notAsLongAsOriginalName = new ImageProcessor.Imaging.CropLayer(90, 0, 0, 0, ImageProcessor.Imaging.CropMode.Percentage); backify.Crop(new Rectangle(25, (100 - this.Height) / 2, 50, this.Height)); hmGreatJobFantasticAmazing.BackgroundImage = backify.Image; grayify.Save(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); ImageFactory grayifyA = new ImageFactory(); grayifyA.Load(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); grayifyA.Saturation(44); grayifyA.Brightness(42); hmGreatJobFantasticAmazing.Image = grayifyA.Image; // Yeahhhhhhhhh I'm going to have to do this another way // panel1.Controls.Add(areYouSeriouslyStillDoingThisLetItGo); // Oh // I can just make another form to draw over and go have turnips with parameters // Also credits to Microsoft Word's "Sentence Case" option as this came out in all caps originally // Measuring string turnt-up-edness was guided by an answer on Stack Overflow by Tom Anderson. String keepThisShortWeNeedToOptimize = sb.ToString().Replace("&", "&&"); Graphics heyGuessWhatGraphicsYeahThatsRight = Graphics.FromImage(new Bitmap(1, 1)); SizeF sure = heyGuessWhatGraphicsYeahThatsRight.MeasureString(keepThisShortWeNeedToOptimize, new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular, GraphicsUnit.Point)); Size sureAgain = sure.ToSize(); int recordThatJim; if (sureAgain.Width >= 300) { recordThatJim = sureAgain.Width + 10; } else { recordThatJim = 300; } CanWeMakeAHoverFormLikeThisIsThisLegal notAsLongInstanceName = new CanWeMakeAHoverFormLikeThisIsThisLegal(recordNao + 150, this.Height, recordThatJim, keepThisShortWeNeedToOptimize); notAsLongInstanceName.Show(); notAsLongInstanceName.BringToFront(); //hmGreatJobFantasticAmazing.BringToFront(); //panel1.Controls.Add(hmGreatJobFantasticAmazing); //hmGreatJobFantasticAmazing.Top = this.Top - 40; //hmGreatJobFantasticAmazing.Left = recordNao + 150; //hmGreatJobFantasticAmazing.BringToFront(); //hmGreatJobFantasticAmazing.Invalidate(); /*hmGreatJobFantasticAmazing.Height = 100; * hmGreatJobFantasticAmazing.Width = 100;*/ }; hmGreatJobFantasticAmazing.MouseLeave += (sender, args) => { /*hmGreatJobFantasticAmazing.ImageAlign = ContentAlignment.MiddleCenter; * hmGreatJobFantasticAmazing.AutoEllipsis = false; * hmGreatJobFantasticAmazing.Width = 40; * hmGreatJobFantasticAmazing.BackColor = Color.Transparent; * //hmGreatJobFantasticAmazing.Font = new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular); * //hmGreatJobFantasticAmazing.ForeColor = Color.White; * hmGreatJobFantasticAmazing.TextAlign = ContentAlignment.MiddleLeft; * hmGreatJobFantasticAmazing.Text = "";*/ try { Application.OpenForms["CanWeMakeAHoverFormLikeThisIsThisLegal"].Close(); } catch (Exception exTurnip) { } hmGreatJobFantasticAmazing.BackgroundImage = null; hmGreatJobFantasticAmazing.Invalidate(); Properties.Settings.Default.stayHere = false; Properties.Settings.Default.Save(); hmGreatJobFantasticAmazing.Image = grayify.Image; }; //openFileToolTip.SetToolTip(hmGreatJobFantasticAmazing, theProcess.MainWindowTitle); //hmGreatJobFantasticAmazing.BackgroundImage = Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap(); hmGreatJobFantasticAmazing.Height = this.Height; hmGreatJobFantasticAmazing.Width = 50; spaceForProcesses.Controls.Add(hmGreatJobFantasticAmazing); } } } } procCount++; } } currentCountProc = artOfficial; }