Esempio n. 1
0
 public TwitterDialog(CanvasControl canvasControl, float dpi, ICanvasEffect effectCanvas)
     : this()
 {
     _canvasControl = canvasControl;
     _dpi           = dpi;
     _effectCanvas  = effectCanvas;
 }
Esempio n. 2
0
 public void Clear()
 {
     Content?.Clear();
     CacheBitmap?.Dispose();
     CacheEffect?.Dispose();
     CacheBitmap = null;
     CacheEffect = null;
 }
Esempio n. 3
0
 private void AddEffect()
 {
     CacheEffect = new Transform2DEffect()
     {
         Source = new ShadowEffect()
         {
             Source     = CacheBitmap,
             BlurAmount = 2,
         },
         TransformMatrix = Matrix3x2.CreateTranslation(3, 3)
     };
 }
Esempio n. 4
0
        public Border()
        {
            this.InitializeComponent();
            this.DataContext = App.Model;


            App.Judge();//判断选区

            Source = new CropEffect
            {
                Source = App.Model.SecondSourceRenderTarget,

                SourceRectangle = App.Model.isAnimated == false?
                                  App.GetBounds(App.Model.SecondSourceRenderTarget.GetPixelColors(), App.Model.Width, App.Model.Height) : //当前选区的边界
                                      App.Model.MaskRect                                                                                  //选区边界
            };
        }
        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();
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
 private void GrayscaleBufferPrevision3_Click(object sender, RoutedEventArgs e)
 {
     grayscale.BufferPrecision = CanvasBufferPrecision.Precision8UIntNormalized;
     canvasEffect = grayscale;
     canvas.Invalidate();
 }
Esempio n. 8
0
 private void GrayscaleBufferPrevision2_Click(object sender, RoutedEventArgs e)
 {
     grayscale.BufferPrecision = CanvasBufferPrecision.Precision32Float;
     canvasEffect = grayscale;
     canvas.Invalidate();
 }
Esempio n. 9
0
 private void GrayscaleBufferPrevision0_Click(object sender, RoutedEventArgs e)
 {
     canvasEffect = temperatureAndTint;
     canvas.Invalidate();
 }