private void Effect() { IFilter imgeFilter = new BurkesDithering(); Bitmap bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnCommon.Image = bitimg; imgeFilter = new GrayscaleBT709(); btnGray.Image = new Bitmap(imgeFilter.Apply(img), 90, 111); imgeFilter = new Sepia(); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnSeperia.Image = bitimg; imgeFilter = new Invert(); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnInvert.Image = bitimg; imgeFilter = new Blur(); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnBlur.Image = bitimg; imgeFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(10, 11), 0.7f, 0.3f); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnJitter.Image = bitimg; imgeFilter = new ChannelFiltering(new IntRange(0, 0), new IntRange(0, 255), new IntRange(0, 255)); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnCyan.Image = bitimg; imgeFilter = new YCbCrExtractChannel(AForge.Imaging.YCbCr.CrIndex); bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111); btnBlackWhite.Image = bitimg; }
private void btnEffectApply_Click(object sender, EventArgs e) { resizerControl.Visible = true; IFilter imgeFilter = default(IFilter); Button effect = (Button)sender; Bitmap imgEffect = img; if (effect.Name == "btnGray") { imgeFilter = new GrayscaleBT709(); } else if (effect.Name == "btnSeperia") { imgeFilter = new Sepia(); } else if (effect.Name == "btnInvert") { imgeFilter = new Invert(); } else if (effect.Name == "btnCommon") { imgeFilter = new BurkesDithering(); } else if (effect.Name == "btnBlur") { imgeFilter = new Blur(); } else if (effect.Name == "btnJitter") { imgeFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(10, 11), 0.7f, 0.3f); } else if (effect.Name == "btnCyan") { imgeFilter = new ChannelFiltering(new IntRange(0, 0), new IntRange(0, 255), new IntRange(0, 255)); } else if (effect.Name == "btnBlackWhite") { imgeFilter = new YCbCrExtractChannel(AForge.Imaging.YCbCr.CrIndex); } imgEffect = imgeFilter.Apply(img); panelImage.BackgroundImage = imgEffect; //img = imgEffect; }
public static Bitmap ApplyFiliter(ImageFiliter imgFilter, Bitmap bmp, byte Value, byte Value2) { Bitmap newImage = null; //ContrastCorrection filter2 = new ContrastCorrection(1.0); //newImage = filter2.Apply(bmp); if (imgFilter != ImageFiliter.None) { IFilter filter3 = Grayscale.CommonAlgorithms.Y; newImage = filter3.Apply(bmp); if (imgFilter == ImageFiliter.Threshold) { IFilter filter = null; if (Value == 0) filter = new Threshold(); else filter = new Threshold(Value); newImage = filter.Apply(newImage); //IterativeThreshold filter = new IterativeThreshold(Value2, Value); //// apply the filter // newImage = filter.Apply(newImage); } if (imgFilter == ImageFiliter.ThresholdWithCarry) { IFilter filter = new ThresholdWithCarry(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.OrderedDithering) { IFilter filter = new OrderedDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.BayerDithering) { IFilter filter = new BayerDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.FloydSteinbergDithering) { IFilter filter = new FloydSteinbergDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.BurkesDithering) { IFilter filter = new BurkesDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.JarvisJudiceNinkeDithering) { IFilter filter = new JarvisJudiceNinkeDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.SierraDithering) { IFilter filter = new SierraDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.StuckiDithering) { IFilter filter = new StuckiDithering(); newImage = filter.Apply(newImage); } else if (imgFilter == ImageFiliter.Convolution) { // create filter //OtsuThreshold filter = new OtsuThreshold(); //// apply the filter //filter.ApplyInPlace(newImage); //// create filter //IterativeThreshold filter = new IterativeThreshold(0); //// apply the filter //newImage = filter.Apply(newImage); int[,] kernel = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; // create filter Convolution filter = new Convolution(kernel); // apply the filter filter.ApplyInPlace(newImage); } newImage = BitmapTo1Bpp(newImage); } else newImage = BitmapTo1Bpp(bmp); //轉換成 1bit bps return newImage; }