private void InitializeEffects() { saturationEffect = new SaturationEffect() { Name = "SaturationEffect", Saturation = item.Saturation, Source = new CompositionEffectSourceParameter("Backdrop") }; contrastEffect = new ContrastEffect() { Name = "ContrastEffect", Contrast = item.Contrast, Source = saturationEffect }; exposureEffect = new ExposureEffect() { Name = "ExposureEffect", Source = contrastEffect, Exposure = item.Exposure, }; temperatureAndTintEffect = new TemperatureAndTintEffect() { Name = "TemperatureAndTintEffect", Source = exposureEffect, Temperature = item.Temperature, Tint = item.Tint }; graphicsEffect = new GaussianBlurEffect() { Name = "Blur", Source = temperatureAndTintEffect, BlurAmount = item.Blur, BorderMode = EffectBorderMode.Hard, }; }
async Task <Uri> Noise(int EffectPercentage) { var level = NoiseLevel.Minimum; if (EffectPercentage <= 35) { level = NoiseLevel.Minimum; } else if (EffectPercentage > 70) { level = NoiseLevel.Maximum; } else { level = NoiseLevel.Medium; } using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new NoiseEffect(contrastEffect) { Level = level }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
private ObservableCollection <VideoEffectsViewModel> CreateEditableEffects() { var effects = new ObservableCollection <VideoEffectsViewModel>(); m_contrastEffect = new ContrastEffect(); effects.Add(new VideoEffectsViewModel(m_contrastEffect, "contrast.png") { Name = "Contrast", MaxValue = 1.0, MinValue = -1.0 }); m_hueSaturationEffect = new HueSaturationEffect(m_contrastEffect); effects.Add(new VideoEffectsViewModel(m_hueSaturationEffect, "saturation.png") { Name = "Hue", MaxValue = 1.0, MinValue = -1.0, PropertyName = "Hue" }); effects.Add(new VideoEffectsViewModel(m_hueSaturationEffect, "saturation.png") { Name = "Saturation", MaxValue = 1.0, MinValue = -1.0, PropertyName = "Saturation" }); m_brightnessEffect = new BrightnessEffect(m_hueSaturationEffect); effects.Add(new VideoEffectsViewModel(m_brightnessEffect, "brightness.png") { Name = "Brightness", MaxValue = 1.0, MinValue = -1.0 }); return(effects); }
private void Load_Completed(LoadedImageSurface sender, LoadedImageSourceLoadCompletedEventArgs e) { IsImageLoading = false; if (e.Status == LoadedImageSourceLoadStatus.Success) { var compositor = Window.Current.Compositor; var brush = compositor.CreateSurfaceBrush(_surface); brush.Stretch = CompositionStretch.UniformToFill; // Create effects chain. saturationEffect = new SaturationEffect() { Name = "SaturationEffect", Saturation = (float)SaturationAmount, Source = new CompositionEffectSourceParameter("image") }; contrastEffect = new ContrastEffect() { Name = "ContrastEffect", Contrast = (float)ContrastAmount, Source = saturationEffect }; exposureEffect = new ExposureEffect() { Name = "ExposureEffect", Source = contrastEffect, Exposure = (float)ExposureAmount, }; temperatureAndTintEffect = new TemperatureAndTintEffect() { Name = "TemperatureAndTintEffect", Source = exposureEffect, Temperature = (float)TemperatureAmount, Tint = (float)TintAmount }; graphicsEffect = new GaussianBlurEffect() { Name = "Blur", Source = temperatureAndTintEffect, BlurAmount = (float)BlurAmount, BorderMode = EffectBorderMode.Hard, }; var graphicsEffectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "SaturationEffect.Saturation", "ExposureEffect.Exposure", "Blur.BlurAmount", "TemperatureAndTintEffect.Temperature", "TemperatureAndTintEffect.Tint", "ContrastEffect.Contrast" }); combinedBrush = graphicsEffectFactory.CreateBrush(); combinedBrush.SetSourceParameter("image", brush); // Composition Brush is what is being applied to the UI Element. CompositionBrush = combinedBrush; } else { LoadImageFromPath("ms-appx:///Assets/StoreLogo.png"); } }
async Task <Uri> Despeckle(int EffectPercentage) { var Level = DespeckleLevel.Minimum; if (EffectPercentage < 25) { Level = DespeckleLevel.Minimum; } if (EffectPercentage > 25 && EffectPercentage <= 50) { Level = DespeckleLevel.Low; } if (EffectPercentage > 50 && EffectPercentage <= 75) { Level = DespeckleLevel.High; } if (EffectPercentage > 75) { Level = DespeckleLevel.Maximum; } using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new DespeckleEffect(contrastEffect) { DespeckleLevel = Level }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
public void Constructor_InitializesExpectedProperties() { // Act var effect = new ContrastEffect(0.5d); // Assert Assert.Equal(0.5d, effect.Contrast); }
private ICanvasImage GetContrastEffect(ICanvasImage source) { var contrastEffects = new ContrastEffect { Source = source, Contrast = (float)(contrast.Value * 0.01) }; return(contrastEffects); }
async Task <Uri> Contrast(int EffectPercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var sharpnessEffect = new ContrastEffect(source) { Level = (EffectPercentage / 100) }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
public void ISerializable_SerializeAndDeserializeCorrectly() { // Arrange var expected = new ContrastEffect(0.5d); var info = MockSerializationInfo <ContrastEffect>(); // Act expected.GetObjectData(info, new StreamingContext()); var actual = new ContrastEffect(info, new StreamingContext()); // Assert Assert.Equal(expected.Contrast, actual.Contrast); }
public static ICanvasImage CreateContrastEffect(IGraphicsEffectSource loadedImage, Slider valueSlider) { valueSlider.Minimum = -1; valueSlider.Maximum = 1; valueSlider.StepFrequency = 0.1; var brightnessEffect = new ContrastEffect { Source = loadedImage, Contrast = 0 }; return(brightnessEffect); }
async Task <Uri> LocalBoost(int EffectPercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new LocalBoostAutomaticEffect(contrastEffect) { Level = (EffectPercentage / 100) }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
async Task <Uri> Exposure(int EffectPercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new ExposureEffect(contrastEffect) { Gain = (EffectPercentage / 67), ExposureMode = ExposureMode.Natural }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
async Task <Uri> ColorAdjust(int RedPercentage, int GreenPercentage, int BluePercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new ColorAdjustEffect(contrastEffect) { Blue = (BluePercentage / 100), Green = (GreenPercentage / 100), Red = (RedPercentage / 100) }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
async Task <Uri> SqureBlur(int EffectPercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new BlurEffect(contrastEffect) { KernelSize = EffectPercentage }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
async Task <Uri> Temperature(int EffectPercentage) { using (var source = new StorageFileImageSource(imageStorageFile)) using (var contrastEffect = new ContrastEffect(source) { Level = 0.6 }) using (var sharpnessEffect = new TemperatureAndTintEffect(contrastEffect) { Temperature = (EffectPercentage / 100) }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } }
private ICanvasImage CreateContrast() { textLabel = requiresWin10; var contrastEffect = new ContrastEffect { Source = bitmapTiger }; // Animation changes the image contrast. animationFunction = elapsedTime => { contrastEffect.Contrast = (float)Math.Sin(elapsedTime * 2); }; return(contrastEffect); }
public void Calculate_AppliesEffectOnHeightMap(double contrast) { // Arrange var data = new double[, ] { { 0d, 0.25d, 0.5d, 0.75d, 1d } }; var heightMap = new HeightMap(data); var expected = MockImageEffect(heightMap, contrast); var effect = new ContrastEffect(contrast); // Act var actual = effect.Calculate(heightMap).Data; // Assert Assert.Equal(expected[0, 0], actual[0, 0]); Assert.Equal(expected[0, 1], actual[0, 1]); Assert.Equal(expected[0, 2], actual[0, 2]); Assert.Equal(expected[0, 3], actual[0, 3]); Assert.Equal(expected[0, 4], actual[0, 4]); }
private CompositionEffectBrush BuildBlurBrush() { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source"), }; BlendEffect blendEffect = new BlendEffect { Background = blurEffect, Foreground = new ColorSourceEffect { Name = "Color", Color = Color.FromArgb(64, 255, 255, 255) }, Mode = BlendEffectMode.SoftLight }; SaturationEffect saturationEffect = new SaturationEffect { Source = blendEffect, Saturation = 2f, }; ContrastEffect contrastEffect = new ContrastEffect { Source = saturationEffect, Contrast = 1f, }; var factory = Compositor.CreateEffectFactory(contrastEffect, new[] { "Blur.BlurAmount", "Color.Color" }); CompositionEffectBrush brush = factory.CreateBrush(); return(brush); }
private void CreateEffects() { _canvasRenderTarget = new CanvasRenderTarget(CanvasControl, (float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height, _canvasBitmap.Dpi); using (var ds = _canvasRenderTarget.CreateDrawingSession()) { ds.DrawImage(_canvasBitmap, new Rect(new Point((Window.Current.Bounds.Width - _canvasBitmap.SizeInPixels.Width) / 2, 0), _canvasBitmap.Size)); } var blur = new GaussianBlurEffect { BlurAmount = _blur, Source = _canvasRenderTarget }; var exposure = new ExposureEffect { Exposure = _exposure, Source = blur }; var saturation = new SaturationEffect { Saturation = _saturation, Source = exposure }; var contrast = new ContrastEffect { Contrast = _contrast, Source = saturation }; _effect = contrast; CanvasControl.Invalidate(); }
private void MainGridLoaded(object sender, RoutedEventArgs e) { m_compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor; m_root = m_compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(MainGrid, m_root); Size imageSize; m_noEffectBrush = CreateBrushFromAsset( "Bruno'sFamily2015 (13)-X2.jpg", out imageSize); m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height; m_sprite = m_compositor.CreateSpriteVisual(); ResizeImage(new Size(MainGrid.ActualWidth, MainGrid.ActualHeight)); m_root.Children.InsertAtTop(m_sprite); // Image with alpha channel as an mask. var alphaMaskEffectDesc = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("Image"), new Transform2DEffect { Name = "MaskTransform", Source = new CompositionEffectSourceParameter("Mask") } } }; m_alphaMaskEffectBrush = m_compositor.CreateEffectFactory( alphaMaskEffectDesc, new[] { "MaskTransform.TransformMatrix" } ).CreateBrush(); m_alphaMaskEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); m_alphaMaskEffectBrush.SetSourceParameter( "Mask", CreateBrushFromAsset("CircleMask.png")); // Arithmetic operations between two images. var arithmeticEffectDesc = new ArithmeticCompositeEffect { Name = "effect", ClampOutput = false, Source1 = new CompositionEffectSourceParameter("Source1"), Source2 = new CompositionEffectSourceParameter("Source2") }; m_arithmeticEffectBrush = m_compositor.CreateEffectFactory( arithmeticEffectDesc, new[] { "effect.MultiplyAmount", "effect.Source1Amount", "effect.Source2Amount", "effect.Offset" } ).CreateBrush(); m_arithmeticEffectBrush.SetSourceParameter( "Source1", m_noEffectBrush); m_arithmeticEffectBrush.SetSourceParameter( "Source2", CreateBrushFromAsset("_P2A8041.jpg")); // Creates a blend effect that combines two images. var foregroundBrush = CreateBrushFromAsset("Checkerboard_100x100.png"); m_blendEffectBrushes = new CompositionEffectBrush[m_supportedBlendModes.Length]; for (int i = 0; i < m_supportedBlendModes.Length; i++) { var blendEffectDesc = new BlendEffect { Mode = m_supportedBlendModes[i], Background = new CompositionEffectSourceParameter("Background"), Foreground = new CompositionEffectSourceParameter("Foreground") }; m_blendEffectBrushes[i] = m_compositor.CreateEffectFactory( blendEffectDesc ).CreateBrush(); m_blendEffectBrushes[i].SetSourceParameter( "Background", m_noEffectBrush); m_blendEffectBrushes[i].SetSourceParameter( "Foreground", foregroundBrush); } // Generates an image containing a solid color. var colorSourceEffectDesc = new ColorSourceEffect // FloodEffect { Name = "effect" }; m_colorSourceEffectBrush = m_compositor.CreateEffectFactory( colorSourceEffectDesc, new[] { "effect.Color" } ).CreateBrush(); // Changes the contrast of an image. var contrastEffectDesc = new ContrastEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_contrastEffectBrush = m_compositor.CreateEffectFactory( contrastEffectDesc, new[] { "effect.Contrast" } ).CreateBrush(); m_contrastEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Changes the exposure of an image. var exposureEffectDesc = new ExposureEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_exposureEffectBrush = m_compositor.CreateEffectFactory( exposureEffectDesc, new[] { "effect.Exposure" } ).CreateBrush(); m_exposureEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the colors of an image by applying a per-channel gamma transfer function. var gammaTransferEffectDesc = new GammaTransferEffect { Name = "effect", RedDisable = false, GreenDisable = false, BlueDisable = false, AlphaDisable = false, Source = new CompositionEffectSourceParameter("Image") }; m_gammaTransferEffectBrush = m_compositor.CreateEffectFactory( gammaTransferEffectDesc, new[] { "effect.RedAmplitude", "effect.RedExponent", "effect.RedOffset", "effect.GreenAmplitude", "effect.GreenExponent", "effect.GreenOffset", "effect.BlueAmplitude", "effect.BlueExponent", "effect.BlueOffset" } ).CreateBrush(); m_gammaTransferEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to monochromatic gray. var grayscaleEffectDesc = new GrayscaleEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_grayscaleEffectBrush = m_compositor.CreateEffectFactory( grayscaleEffectDesc ).CreateBrush(); m_grayscaleEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the color of an image by rotating its hue values. var hueRotationEffectDesc = new HueRotationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_hueRotationEffectBrush = m_compositor.CreateEffectFactory( hueRotationEffectDesc, new[] { "effect.Angle" } ).CreateBrush(); m_hueRotationEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Inverts the colors of an image. var invertEffectDesc = new InvertEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_invertEffectBrush = m_compositor.CreateEffectFactory( invertEffectDesc ).CreateBrush(); m_invertEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the saturation of an image. var saturationEffectDesc = new SaturationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_saturateEffectBrush = m_compositor.CreateEffectFactory( saturationEffectDesc, new[] { "effect.Saturation" } ).CreateBrush(); m_saturateEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to sepia tones. var supportedAlphaModes = new[] { CanvasAlphaMode.Premultiplied, CanvasAlphaMode.Straight }; m_sepiaEffectBrushes = new CompositionEffectBrush[supportedAlphaModes.Length]; for (int i = 0; i < supportedAlphaModes.Length; i++) { var sepiaEffectDesc = new SepiaEffect { Name = "effect", AlphaMode = supportedAlphaModes[i], Source = new CompositionEffectSourceParameter("Image") }; m_sepiaEffectBrushes[i] = m_compositor.CreateEffectFactory( sepiaEffectDesc, new[] { "effect.Intensity" } ).CreateBrush(); m_sepiaEffectBrushes[i].SetSourceParameter( "Image", m_noEffectBrush); } // Adjusts the temperature and/or tint of an image. var temperatureAndTintEffectDesc = new TemperatureAndTintEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_temperatureAndTintEffectBrush = m_compositor.CreateEffectFactory( temperatureAndTintEffectDesc, new[] { "effect.Temperature", "effect.Tint" } ).CreateBrush(); m_temperatureAndTintEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Applies a 2D affine transform matrix to an image. var transform2DEffectDesc = new Transform2DEffect { TransformMatrix = new Matrix3x2( -1, 0, 0, 1, m_sprite.Size.X, 0), Source = new CompositionEffectSourceParameter("Image") }; m_transform2DEffectBrush = m_compositor.CreateEffectFactory( transform2DEffectDesc ).CreateBrush(); m_transform2DEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // For simplying UI states switch, put effect parameter grids in an array m_effectParamsGrids = new Grid[(int)EffectType.NumEffectTypes]; m_effectParamsGrids[(int)EffectType.NoEffect] = null; m_effectParamsGrids[(int)EffectType.AlphaMask] = AlphaMaskParams; m_effectParamsGrids[(int)EffectType.Arithmetic] = ArithmeticParams; m_effectParamsGrids[(int)EffectType.Blend] = BlendParams; m_effectParamsGrids[(int)EffectType.ColorSource] = ColorSourceParams; m_effectParamsGrids[(int)EffectType.Contrast] = ContrastParams; m_effectParamsGrids[(int)EffectType.Exposure] = ExposureParams; m_effectParamsGrids[(int)EffectType.GammaTransfer] = GammaTransferParams; m_effectParamsGrids[(int)EffectType.Grayscale] = null; m_effectParamsGrids[(int)EffectType.HueRotation] = HueRotationParams; m_effectParamsGrids[(int)EffectType.Invert] = null; m_effectParamsGrids[(int)EffectType.Saturation] = SaturationParams; m_effectParamsGrids[(int)EffectType.Sepia] = SepiaParams; m_effectParamsGrids[(int)EffectType.TemperatureAndTint] = TemperatureAndTintParams; m_effectParamsGrids[(int)EffectType.Transform2D] = null; // Same as grids m_effectBrushes = new CompositionBrush[(int)EffectType.NumEffectTypes]; m_effectBrushes[(int)EffectType.NoEffect] = m_noEffectBrush; m_effectBrushes[(int)EffectType.AlphaMask] = m_alphaMaskEffectBrush; m_effectBrushes[(int)EffectType.Arithmetic] = m_arithmeticEffectBrush; m_effectBrushes[(int)EffectType.Blend] = m_blendEffectBrushes[m_activeBlendMode]; m_effectBrushes[(int)EffectType.ColorSource] = m_colorSourceEffectBrush; m_effectBrushes[(int)EffectType.Contrast] = m_contrastEffectBrush; m_effectBrushes[(int)EffectType.Exposure] = m_exposureEffectBrush; m_effectBrushes[(int)EffectType.GammaTransfer] = m_gammaTransferEffectBrush; m_effectBrushes[(int)EffectType.Grayscale] = m_grayscaleEffectBrush; m_effectBrushes[(int)EffectType.HueRotation] = m_hueRotationEffectBrush; m_effectBrushes[(int)EffectType.Invert] = m_invertEffectBrush; m_effectBrushes[(int)EffectType.Saturation] = m_saturateEffectBrush; m_effectBrushes[(int)EffectType.Sepia] = m_sepiaEffectBrushes[m_activeSepiaAlphaMode]; m_effectBrushes[(int)EffectType.TemperatureAndTint] = m_temperatureAndTintEffectBrush; m_effectBrushes[(int)EffectType.Transform2D] = m_transform2DEffectBrush; this.InitializeValues(); }
private ObservableCollection<VideoEffectsViewModel> CreateEditableEffects() { var effects = new ObservableCollection<VideoEffectsViewModel>(); m_contrastEffect = new ContrastEffect(); effects.Add(new VideoEffectsViewModel(m_contrastEffect, "contrast.png") { Name = "Contrast", MaxValue = 1.0, MinValue = -1.0 }); m_hueSaturationEffect = new HueSaturationEffect(m_contrastEffect); effects.Add(new VideoEffectsViewModel(m_hueSaturationEffect, "saturation.png") { Name = "Hue", MaxValue = 1.0, MinValue = -1.0, PropertyName = "Hue" }); effects.Add(new VideoEffectsViewModel(m_hueSaturationEffect, "saturation.png") { Name = "Saturation", MaxValue = 1.0, MinValue = -1.0, PropertyName = "Saturation" }); m_brightnessEffect = new BrightnessEffect(m_hueSaturationEffect); effects.Add(new VideoEffectsViewModel(m_brightnessEffect, "brightness.png") { Name = "Brightness", MaxValue = 1.0, MinValue = -1.0 }); return effects; }
private async void btnUpload_Clicked(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); // Pick only one file once a time StorageFile file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read)) { cl = new CanvasCommandList(canvas); using (CanvasDrawingSession clds = cl.CreateDrawingSession()) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream); clds.DrawImage( CanvasBitmap.CreateFromSoftwareBitmap(canvas, await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Rgba16, BitmapAlphaMode.Premultiplied))); } blur = new GaussianBlurEffect { Source = cl, BlurAmount = (float)gaussianBlurAmountSlider.Value }; hueRotation = new HueRotationEffect { Source = blur, Angle = (float)hueRotationAmountSlider.Value / 100f * 360f }; contrast = new ContrastEffect { Source = hueRotation, Contrast = (float)(contrastAmountSlider.Value - 50f) / 50f }; saturation = new SaturationEffect { Source = contrast, Saturation = (float)saturationAmountSlider.Value / 100f }; temperatureAndTint = new TemperatureAndTintEffect { Source = saturation, Temperature = (float)(temperatureAmountSlider.Value - 50f) / 50f, Tint = (float)(tintAmountSlider.Value - 50f) / 50f }; grayscale = new GrayscaleEffect { Source = temperatureAndTint }; canvasEffect = saturation; // CanvasControl.Invalidate Method iIndicates that the contents of the CanvasControl need to be redrawn. // Calling Invalidate results in the Draw event being raised shortly afterward. // // Reference: https://microsoft.github.io/Win2D/html/M_Microsoft_Graphics_Canvas_UI_Xaml_CanvasControl_Invalidate.htm canvas.Invalidate(); gaussianBlurAmountSlider.IsEnabled = true; hueRotationAmountSlider.IsEnabled = true; contrastAmountSlider.IsEnabled = true; saturationAmountSlider.IsEnabled = true; temperatureAmountSlider.IsEnabled = true; tintAmountSlider.IsEnabled = true; grayscaleBufferPrevision.IsEnabled = true; var image = new BitmapImage(); await image.SetSourceAsync(fileStream); } }
public CanvasRenderTarget applyEdgeDetectionEffects(CanvasBitmap workingBitmap) { //CanvasBitmap workingBitmap = SelectWorkingBitmap(useOriginalBitmap); if (workingBitmap != null) { int ww = (int)workingBitmap.SizeInPixels.Width; int hh = (int)workingBitmap.SizeInPixels.Height; //GrayscaleEffect grayscaleEffect = new GrayscaleEffect(); //grayscaleEffect.Source=canvasBitmap; ContrastEffect contrastEffect = new ContrastEffect(); contrastEffect.Contrast = (float)edgeDetectionContrast; contrastEffect.Source = workingBitmap; ExposureEffect exposureEffect = new ExposureEffect(); exposureEffect.Source = contrastEffect; exposureEffect.Exposure = (float)edgeDetectionExposure; EdgeDetectionEffect edgeDetectionEffect = new EdgeDetectionEffect(); edgeDetectionEffect.Source = exposureEffect; edgeDetectionEffect.Amount = (float)edgeDetectionAmount; edgeDetectionEffect.BlurAmount = (float)edgeDetectionBlurAmount; //edgeDetectionEffect.OverlayEdges = true; //edgeDetectionEffect.Mode = EdgeDetectionEffectMode.Prewitt; GrayscaleEffect grayscaleEffect = null; if (edgeDetectionGrayscale) { grayscaleEffect = new GrayscaleEffect(); grayscaleEffect.Source = exposureEffect; edgeDetectionEffect.Source = grayscaleEffect; } InvertEffect invertEdgeEffect = null; if (edgeDetectionMaskInvert) { invertEdgeEffect = new InvertEffect(); invertEdgeEffect.Source = edgeDetectionEffect; } BlendEffect blendEffect = null; if (edgeDetectionOverlayImage) { OpacityEffect opacityEffect = new OpacityEffect(); opacityEffect.Opacity = (float)edgeDetectionOverlayOpacity; opacityEffect.Source = workingBitmap; blendEffect = new BlendEffect(); blendEffect.Foreground = edgeDetectionEffect; blendEffect.Background = opacityEffect; if (edgeDetectionMaskInvert) { //blendEffect.Background = invertEdgeEffect; //blendEffect.Foreground = opacityEffect; InvertEffect invertOrgEffect = new InvertEffect(); invertOrgEffect.Source = opacityEffect; blendEffect.Background = invertOrgEffect; } blendEffect.Mode = edgeDetectionBlendEffectMode; } //if (canvasRenderTarget != null) // canvasRenderTarget.Dispose(); CanvasRenderTarget canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), ww, hh, canvasBitmap.Dpi); using (var session = canvasRenderTarget.CreateDrawingSession()) { if (edgeDetectionOverlayImage) { session.DrawImage(blendEffect); } else { if (edgeDetectionMaskInvert) { session.DrawImage(invertEdgeEffect); } else { session.DrawImage(edgeDetectionEffect); } } } return(canvasRenderTarget); } return(null); }