private void ApplyFilter(bool preview) { cmbInvertColoursType.Enabled = chkInvertColours.Checked; cmbFilterType.Enabled = chkSwapColours.Checked; lblFixedValue.Text = "Fixed Value: " + trcFixedValue.Value.ToString(); Bitmap bitmapResult = null; if (picSource.Image == null) { return; } if (preview == true) { bitmapResult = new Bitmap(picSource.Image); } else { bitmapResult = new Bitmap(sourceBitmap); } if (bitmapResult == null) { return; } if (chkFlipPixels.Checked == true) { bitmapResult = bitmapResult.FlipPixels(); } if (chkInvertColours.Checked == true) { ColourInversionType inversionType = (ColourInversionType)cmbInvertColoursType.SelectedItem; bitmapResult = bitmapResult.InvertColors(inversionType); } if (chkSwapColours.Checked == true) { ColourSwapType swapType = (ColourSwapType)cmbFilterType.SelectedItem; bitmapResult = bitmapResult.SwapColors(swapType, (byte)trcFixedValue.Value); } if (bitmapResult != null) { if (preview == true) { picResult.Image = bitmapResult; } else { resultBitmap = bitmapResult; } } }
public static Bitmap InvertColors(Bitmap sourceImage, ColourInversionType inversionType) { List <pixel> pixelListSource = imageFunctions.GetPixelListFromBitmap(sourceImage); List <pixel> pixelListResult = null; byte byte255 = 255; switch (inversionType) { case ColourInversionType.All: { pixelListResult = (from t in pixelListSource select new pixel { blue = (byte)(byte255 - t.blue), red = (byte)(byte255 - t.red), green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); //foreach (pixel item in pixelListSource) //{ // byte[] x = item.GetColorBytes(); // int coX = item.pixelX; // int coY = item.pixelY; // x[0] = (byte)(byte255 - x[0]); // x[1] = (byte)(byte255 - x[1]); // x[2] = (byte)(byte255 - x[2]); // pixelListResult.Add(new pixel(x,coX,coY)); //} break; } case ColourInversionType.Blue: { pixelListResult = (from t in pixelListSource select new pixel { blue = (byte)(byte255 - t.blue), red = t.red, green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.Green: { pixelListResult = (from t in pixelListSource select new pixel { blue = t.blue, red = t.red, green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } case ColourInversionType.Red: { pixelListResult = (from t in pixelListSource select new pixel { blue = t.blue, red = (byte)(byte255 - t.green), green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.BlueRed: { pixelListResult = (from t in pixelListSource select new pixel { blue = (byte)(byte255 - t.blue), red = (byte)(byte255 - t.red), green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.BlueGreen: { pixelListResult = (from t in pixelListSource select new pixel { blue = (byte)(byte255 - t.blue), red = t.red, green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } case ColourInversionType.RedGreen: { pixelListResult = (from t in pixelListSource select new pixel { blue = t.blue, red = (byte)(byte255 - t.blue), green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } } Bitmap resultBitmap = imageFunctions.GetBitmapFromPixelList(pixelListResult, sourceImage.Width, sourceImage.Height); return(resultBitmap); }
public static Bitmap InvertColors(this Bitmap sourceImage, ColourInversionType inversionType) { List <ArgbPixel> pixelListSource = GetPixelListFromBitmap(sourceImage); List <ArgbPixel> pixelListResult = null; byte byte255 = 255; switch (inversionType) { case ColourInversionType.All: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = (byte)(byte255 - t.blue), red = (byte)(byte255 - t.red), green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } case ColourInversionType.Blue: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = (byte)(byte255 - t.blue), red = t.red, green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.Green: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = t.blue, red = t.red, green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } case ColourInversionType.Red: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = t.blue, red = (byte)(byte255 - t.green), green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.BlueRed: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = (byte)(byte255 - t.blue), red = (byte)(byte255 - t.red), green = t.green, alpha = t.alpha, }).ToList(); break; } case ColourInversionType.BlueGreen: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = (byte)(byte255 - t.blue), red = t.red, green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } case ColourInversionType.RedGreen: { pixelListResult = (from t in pixelListSource select new ArgbPixel { blue = t.blue, red = (byte)(byte255 - t.blue), green = (byte)(byte255 - t.green), alpha = t.alpha, }).ToList(); break; } } Bitmap resultBitmap = GetBitmapFromPixelList(pixelListResult, sourceImage.Width, sourceImage.Height); return(resultBitmap); }