public void ColorizeBlock(int blockID, byte regionID) { regions[blockID] = regionID; if (Colored == null) { Colored = new Bitmap(originalMap); } Rectangle rect = CalculateRectangle(blockID); int huetransform; if (regionID < regionHUE.Length) { huetransform = regionID == 0xFF ? 0 : regionHUE[regionID]; } else { huetransform = 0; } if (regionID == 255) { return; } HueModifier hue = new HueModifier(huetransform); hue.ApplyInPlace(Colored, rect); }
public void ColorizeBlock(Rectangle rect) { if (Colored == null) { Colored = new Bitmap(originalMap); } HueModifier hue = new HueModifier(huetransformator); hue.ApplyInPlace(Colored, rect); pictureBox3.Image = Colored; }
public Tuple <Bitmap, Json> CreateImage() { if (_leftEyes.Count == 0 || _rightEyes.Count == 0 || _noses.Count == 0 || _mouths.Count == 0) { return(null); } Random rnd = new Random(); Json json = new Json(); json.angle = 270; json.type = "Pop face mix"; var leftEyePath = _leftEyes.ElementAt(rnd.Next(0, _leftEyes.Count() - 1)); json.addItem(leftEyePath, "Oeil gauche"); var leftEye = FastLoad(leftEyePath); var rightEyePath = _rightEyes.ElementAt(rnd.Next(0, _rightEyes.Count() - 1)); json.addItem(rightEyePath, "Oeil droit"); var rightEye = FastLoad(rightEyePath); var nosePath = _noses.ElementAt(rnd.Next(0, _noses.Count() - 1)); json.addItem(nosePath, "Nez"); var nose = FastLoad(nosePath); var mouthPath = _mouths.ElementAt(rnd.Next(0, _mouths.Count() - 1)); json.addItem(mouthPath, "Bouche"); var mouth = FastLoad(mouthPath); var target = new Bitmap(mouth.Width, mouth.Height, mouth.PixelFormat); target.SetResolution(mouth.HorizontalResolution, mouth.VerticalResolution); var graphics = Graphics.FromImage(target); graphics.CompositingMode = CompositingMode.SourceOver; pop(graphics, mouth); pop(graphics, nose); pop(graphics, leftEye); pop(graphics, rightEye); var filterHueModifier = new HueModifier(rnd.Next(0, 359)); filterHueModifier.ApplyInPlace(target); return(new Tuple <Bitmap, Json>(target, json)); }
private void ChangeHueC(object obj) { Bitmap bmp = null; try { bmp = (Bitmap)this.Temporary.Clone(); } catch { } hueFiltter.Hue = HueValue; if (bmp != null) { hueFiltter.ApplyInPlace(bmp); } Images.Instance.CurrentBitmap = bmp; Images.Instance.NotifyImages(); try { UndoRedoModel.Instance.UndoStack.Pop(); Images.Instance.UndoBr--; } catch { } }
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) {