public void Should_Convert_to_bitmap_with_same_width_height( [Values(1, 100, 255, 256, 257, 1024)] int width, [Values(1, 10, 255, 256, 257, 1024)] int height) { var source = CreateBitmap(width, height, 96, 96); var actual = (BitmapSource)_sut.Convert(source, typeof(BitmapSource), null, CultureInfo.InvariantCulture); Assert.AreEqual(width, actual.Width); Assert.AreEqual(height, actual.Height); }
public T Convert(T source, int bound) { var converter = new GrayscaleConverter <T>(); var dst = new MyImage(source.Width, source.Height); object img = dst; img = converter.Convert(source); for (int i = 0; i < source.Width; i++) { for (int j = 0; j < source.Height; j++) { int recolor = dst[i, j].R > bound ? 255 : 0; dst[i, j] = Color.FromArgb(recolor, recolor, recolor); } } return((T)img); }
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(value is BitmapSource source ? GrayscaleConverter.Convert(source) : DependencyProperty.UnsetValue); }