private void SetEdgeC(object obj) { Bitmap bmp = null; try { bmp = (Bitmap)Images.Instance.CurrentBitmap.Clone(); } catch { } Bitmap bmpselected = null; try { bmpselected = (Bitmap)Images.Instance.SelectedBitmap.Clone(); } catch { } if (partarea == true && bmpselected != null) { edgesFilter.ApplyInPlace(bmpselected); Graphics newImage = Graphics.FromImage(bmp); newImage.DrawImage(bmpselected, (int)SelectedPoints.selectPointForEfX, (int)SelectedPoints.selectPointForEfY, bmpselected.Width, bmpselected.Height); } else if (bmp != null) { edgesFilter.ApplyInPlace(bmp); } Images.Instance.CurrentBitmap = bmp; Images.Instance.NotifyImages(); this.Temporary = bmp; }
void SimpleToolStripMenuItemClick(object sender, EventArgs e) { //jika gambar kosong/null maka akan mengembalikan nilai kosong/null if (gambar == null) { return; } //clone variable gambar ke variable gambar2 dan menginisiasi class Rectangle //dan menerapkan format pixel 24bppRgb gambar2 = gambar.Clone(new Rectangle(0, 0, gambar.Width, gambar.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); //convert ke grayscale terlebih dahulu lalu aplikasikan filter edges. //inisiasi filter grayscale disertai argumen Grayscale grayscaleF = new Grayscale(0.2125, 0.7154, 0.0721); //aplikasikan filter grayscale ke gambar2 gambar2 = grayscaleF.Apply(gambar2); //inisiasi filter Edges Edges edges = new Edges(); //aplikasikan filter pada gambar2 edges.ApplyInPlace(gambar2); //tampilkan pada picturebox2 pictureBox2.Image = gambar2; }
private void Edges_Filter_Process() { var filter = new Edges(); AddLog("filtr Edges na " + _view.CurrentFile); filter.ApplyInPlace(_image); Thread.Sleep(200); }
private void Edges_Filter_Process(object callback) { var filter = new Edges(); AddLog("filtr Edges na " + _view.CurrentFile); filter.ApplyInPlace(_image); Thread.Sleep(200); ((AutoResetEvent)callback).Set(); }
public static Image ApplyImageProperties(byte[] blobContent, ImageProperties properties) { Bitmap image = null; try { using (var ms = new MemoryStream(blobContent)) { image = (Bitmap)System.Drawing.Image.FromStream(ms, false, false); image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); if (properties.Crop != null) { AForge.Imaging.Filters.Crop filter = new AForge.Imaging.Filters.Crop(new Rectangle(properties.Crop.XOffset, properties.Crop.YOffset, properties.Crop.CropWidth, properties.Crop.CropHeight)); image = filter.Apply(image); } if (properties.ImageWidth != properties.OriginalWidth || properties.ImageHeight != properties.OriginalHeight) { var filter = new ResizeBicubic(properties.ImageWidth, properties.ImageHeight); image = filter.Apply(image); } if (properties.Colors != null) { if (properties.Colors.TransparentColor != null) { image.MakeTransparent(ColorTranslator.FromHtml("#" + properties.Colors.TransparentColor)); } var brightness = properties.Colors.Brightness; var bfilter = new BrightnessCorrection(brightness); bfilter.ApplyInPlace(image); var contrast = properties.Colors.Contrast; var cfilter = new ContrastCorrection(contrast); cfilter.ApplyInPlace(image); if (properties.Colors.Hue != 0) { var hue = properties.Colors.Hue; HueModifier filter = new HueModifier(hue); filter.ApplyInPlace(image); } var saturation = properties.Colors.Saturation; var sfilter = new SaturationCorrection(saturation * 0.01f); sfilter.ApplyInPlace(image); } # region Effects if (!String.IsNullOrEmpty(properties.Effects)) { var effects = properties.Effects.Split(';'); foreach (var item in effects) { switch (item) { case "Grayscale": var g = new Grayscale(0.2125, 0.7154, 0.0721); image = g.Apply(image); break; case "Sepia": var s = new Sepia(); image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); s.ApplyInPlace(image); break; case "Rotate Channels": image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); var r = new RotateChannels(); r.ApplyInPlace(image); break; case "Invert": var i = new Invert(); i.ApplyInPlace(image); break; case "Blur": var b = new Blur(); b.ApplyInPlace(image); break; case "Gaussian Blur": var gb = new GaussianBlur(4, 11); gb.ApplyInPlace(image); break; case "Convolution": int[,] kernel = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; var c = new Convolution(kernel); c.ApplyInPlace(image); break; case "Edges": var e = new Edges(); e.ApplyInPlace(image); break; } } } # endregion } } catch (Exception) {
public void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { time.Start(); Bitmap img = (Bitmap)eventArgs.Frame.Clone(); if (flag_rotate != 0) { if (flag_rotate == 1) { img.RotateFlip(RotateFlipType.Rotate90FlipNone); } else if (flag_rotate == 2) { img.RotateFlip(RotateFlipType.Rotate180FlipNone); } else { img.RotateFlip(RotateFlipType.Rotate270FlipNone); } } if (flag_smooth == 1) { img = grayscale.Apply(img); } if (trackBar1.Value != 0) { img = br.Apply(img); } if (flag_flipX == 1) { img.RotateFlip(RotateFlipType.RotateNoneFlipX); } if (flag_flipY == 1) { img.RotateFlip(RotateFlipType.RotateNoneFlipY); } if (flag_sharpen == 1) { sharpen.ApplyInPlace(img); } if (flag_treshold == 1) { marker.ApplyInPlace(img); } if (flag_edge == 1) { rubovi.ApplyInPlace(img); } if (flag_dither == 1) { poster_filter.ApplyInPlace(img); } if (flag_invert == 1) { invert_filter.ApplyInPlace(img); } pbx_image.Image = img; time.Stop(); lbl_time.Text = "Frame times: " + time.ElapsedMilliseconds + " ms"; time.Reset(); }