/// <summary> /// Constructor principal del programa /// </summary> public Form1() { InitializeComponent(); servers.Add("http://172.24.65.181:89/ImageProcessingWebService"); servers.Add("http://172.24.65.181:89/ImageProcessingWebService"); servers.Add("http://172.24.65.181:89/ImageProcessingWebService"); servers.Add("http://172.24.65.181:89/ImageProcessingWebService"); traditionalFilter = new TraditionalImageFiltering(); this.ConnectionManager = new ConnectionManager(); optimizedFilter = new OptimizedImageFiltering(); colorSubstitution = new ColorSubstitutionFilter(); images = new ArrayList(); setFiltersType(); availableFilters.SelectedIndex = 0; imageContainer.SizeMode = PictureBoxSizeMode.StretchImage; CPUusage.Text = CPUCounter.NextValue() + "%"; t.Interval = 750; t.Enabled = true; timer1_Tick(null, null); t.Tick += new EventHandler(timer1_Tick); }
public static void DoSomething(string path) { var image = Image.Load(path); var fromRange = new ColorRange() { From = new Rgba32(250, 255, 255), To = new Rgba32(255, 255, 255), }; var toRange = new ColorRange() { From = new Rgba32(72, 110, 146), To = new Rgba32(152, 187, 214), }; var filter = new ColorSubstitutionFilter(image, ColorSubstitutionType.SubstitytionByLinearRange, fromRange, toRange); AdaptiveWorkflow workflow = new AdaptiveWorkflow(); image = workflow.AddFilter(filter); using (FileStream fs = new FileStream(@"C:\Users\r_bon\Pictures\Camera Roll\" + Guid.NewGuid() + ".png", FileMode.OpenOrCreate)) { image.SaveAsPng(fs); } }
public static Bitmap Whitenize(Bitmap src, int threshold, bool demo) { ColorSubstitutionFilter f = new ColorSubstitutionFilter(); f.ThresholdValue = threshold; f.SourceColor = Color.White; f.NewColor = demo ? Color.LightPink : Color.Transparent; return(ColorSubstitution(src, f)); }
private static Bitmap ColorSubstitution(Bitmap sourceBitmap, ColorSubstitutionFilter filterData) { Bitmap resultBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format32bppArgb); BitmapData sourceData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData resultData = resultBitmap.LockBits(new Rectangle(0, 0, resultBitmap.Width, resultBitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); byte[] resultBuffer = new byte[resultData.Stride * resultData.Height]; Marshal.Copy(sourceData.Scan0, resultBuffer, 0, resultBuffer.Length); sourceBitmap.UnlockBits(sourceData); byte sourceRed = 0, sourceGreen = 0, sourceBlue = 0, sourceAlpha = 0; int resultRed = 0, resultGreen = 0, resultBlue = 0; byte newRedValue = filterData.NewColor.R; byte newGreenValue = filterData.NewColor.G; byte newBlueValue = filterData.NewColor.B; byte newAlphaValue = filterData.NewColor.A; byte redFilter = filterData.SourceColor.R; byte greenFilter = filterData.SourceColor.G; byte blueFilter = filterData.SourceColor.B; byte minValue = 0; byte maxValue = 255; for (int k = 0; k < resultBuffer.Length; k += 4) { sourceAlpha = resultBuffer[k + 3]; if (sourceAlpha != 0) { sourceBlue = resultBuffer[k]; sourceGreen = resultBuffer[k + 1]; sourceRed = resultBuffer[k + 2]; if ((sourceBlue < blueFilter + filterData.ThresholdValue && sourceBlue > blueFilter - filterData.ThresholdValue) && (sourceGreen < greenFilter + filterData.ThresholdValue && sourceGreen > greenFilter - filterData.ThresholdValue) && (sourceRed < redFilter + filterData.ThresholdValue && sourceRed > redFilter - filterData.ThresholdValue)) { resultBlue = blueFilter - sourceBlue + newBlueValue; if (resultBlue > maxValue) { resultBlue = maxValue; } else if (resultBlue < minValue) { resultBlue = minValue; } resultGreen = greenFilter - sourceGreen + newGreenValue; if (resultGreen > maxValue) { resultGreen = maxValue; } else if (resultGreen < minValue) { resultGreen = minValue; } resultRed = redFilter - sourceRed + newRedValue; if (resultRed > maxValue) { resultRed = maxValue; } else if (resultRed < minValue) { resultRed = minValue; } resultBuffer[k] = (byte)resultBlue; resultBuffer[k + 1] = (byte)resultGreen; resultBuffer[k + 2] = (byte)resultRed; resultBuffer[k + 3] = newAlphaValue; } } } Marshal.Copy(resultBuffer, 0, resultData.Scan0, resultBuffer.Length); resultBitmap.UnlockBits(resultData); return(resultBitmap); }
public Bitmap colorSubstitution(Bitmap image, ColorSubstitutionFilter changer) { Bitmap bmpNew = new Bitmap(image); BitmapData bmpData = bmpNew.LockBits(new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); IntPtr ptr = bmpData.Scan0; byte[] resultBuffer = new byte[bmpData.Stride * bmpNew.Height]; Marshal.Copy(ptr, resultBuffer, 0, resultBuffer.Length); int limit = resultBuffer.Length; //almacenamiento de variables temporales byte sourceRed = 0, sourceGreen = 0, sourceBlue = 0, sourceAlpha = 0; int resultRed = 0, resultGreen = 0, resultBlue = 0; byte minValue = 0; byte maxValue = 255; Color sourceColor = changer.getSourceColor(); Color newColor = changer.getNewColor(); int colorThreshold = changer.getThreshold(); for (int k = 0; k < limit; k += 4) { sourceAlpha = resultBuffer[k + 3]; if (sourceAlpha != 0) { //obtener valores del pixel sourceBlue = resultBuffer[k]; sourceGreen = resultBuffer[k + 1]; sourceRed = resultBuffer[k + 2]; if ((sourceBlue < sourceColor.B + colorThreshold && sourceBlue > sourceColor.B - colorThreshold) && (sourceGreen < sourceColor.G + colorThreshold && sourceGreen > sourceColor.G - colorThreshold) && (sourceRed < sourceColor.R + colorThreshold && sourceRed > sourceColor.R - colorThreshold)) { resultBlue = sourceColor.B - sourceBlue + newColor.B; if (resultBlue > maxValue) { resultBlue = maxValue; } else if (resultBlue < minValue) { resultBlue = minValue; } resultGreen = sourceColor.G - sourceGreen + newColor.G; if (resultGreen > maxValue) { resultGreen = maxValue; } else if (resultGreen < minValue) { resultGreen = minValue; } resultRed = sourceColor.R - sourceRed + newColor.R; if (resultRed > maxValue) { resultRed = maxValue; } else if (resultRed < minValue) { resultRed = minValue; } resultBuffer[k] = (byte)resultBlue; resultBuffer[k + 1] = (byte)resultGreen; resultBuffer[k + 2] = (byte)resultRed; resultBuffer[k + 3] = sourceAlpha; } } } Console.WriteLine("SE aplicó un filtro a la imagen"); Marshal.Copy(resultBuffer, 0, ptr, resultBuffer.Length); bmpNew.UnlockBits(bmpData); bmpData = null; resultBuffer = null; saveImage(bmpNew); return(bmpNew); }