private CompositionDrawingSurface SampleImageColor(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget) { // Extract the color to tint the blur with Color predominantColor = ExtractPredominantColor(bitmap.GetPixelColors(), bitmap.Size); Size sizeSource = bitmap.Size; if (sizeTarget.IsEmpty) { sizeTarget = sizeSource; } // Create a heavily blurred version of the image GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 20.0f }; CompositionDrawingSurface surface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(surface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.FillRectangle(destination, predominantColor); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height), .6f); } return(surface); }
#pragma warning disable 1998 public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size) { using (var ds = CanvasComposition.CreateDrawingSession(surface)) { ds.Clear(Colors.Transparent); ds.FillCircle(new Vector2(_radius, _radius), _radius, _color); } }
/// <summary> /// Creates an instance of the ColorBloomTransitionHelper. /// Any visuals to be later created and animated will be hosted within the specified UIElement. /// </summary> public ColorBloomTransitionHelper(UIElement hostForVisual) { this.hostForVisual = hostForVisual; // we have an element in the XAML tree that will host our Visuals var visual = ElementCompositionPreview.GetElementVisual(hostForVisual); _compositor = visual.Compositor; // create a container // adding children to this container adds them to the live visual tree _containerForVisuals = _compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals); _canvasDevice = new CanvasDevice(); _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); // Create the circle mask _circleMaskSurface = LoadCircle(200, Colors.White); }
public static IImageLoader CreateImageLoader(CompositionGraphicsDevice graphicsDevice) { var imageLoader = new ImageLoader(); imageLoader.Initialize(graphicsDevice); return(imageLoader); }
public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, ContentDrawer drawer) { Debug.Assert(_surface != null); _drawer = drawer; await _drawer.Draw(device, drawingLock, _surface, _surface.Size); }
public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size) { using (var ds = CanvasComposition.CreateDrawingSession(surface)) { ds.Clear(_backgroundColor); ds.DrawText(_text, new Rect(0, 0, surface.Size.Width, surface.Size.Height), _textColor, _textFormat); } }
private CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget) { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 10.0f, BorderMode = EffectBorderMode.Hard, }; float fDownsample = .3f; Size sizeSource = bitmap.Size; if (sizeTarget == Size.Empty) { sizeTarget = sizeSource; } sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample); CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(blurSurface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height)); ds.FillRectangle(destination, Windows.UI.Color.FromArgb(60, 0, 0, 0)); } return(blurSurface); }
private void Setup() { _canvasDevice = new CanvasDevice(); _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice( Windows.UI.Xaml.Window.Current.Compositor, _canvasDevice); _compositor = Windows.UI.Xaml.Window.Current.Compositor; _surface = _compositionGraphicsDevice.CreateDrawingSurface( new Windows.Foundation.Size(400, 400), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); // This is the only value that currently works with // the composition APIs. var visual = _compositor.CreateSpriteVisual(); visual.RelativeSizeAdjustment = Vector2.One; var brush = _compositor.CreateSurfaceBrush(_surface); brush.HorizontalAlignmentRatio = 0.5f; brush.VerticalAlignmentRatio = 0.5f; brush.Stretch = CompositionStretch.Uniform; visual.Brush = brush; ElementCompositionPreview.SetElementChildVisual(this, visual); StartCaptureInternal(MainPage.targetcap); }
private void Form1_Load(object sender, EventArgs e) { // This container visual is optional - content could go directly into the root // containerVisual. This lets you overlay just the picture box, and you could add // other container visuals to overlay other areas of the UI. pictureOverlayVisual = compositor.CreateContainerVisual(); pictureOverlayVisual.Offset = new Vector3(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top, 0); pictureOverlayVisual.Size = new Vector2(pictureBox1.Width, pictureBox1.Height); containerVisual.Children.InsertAtTop(pictureOverlayVisual); rectWidth = pictureBox1.Width / 2; rectHeight = pictureBox1.Height / 2; // Get graphics device. compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice); // Create surface. var noiseDrawingSurface = compositionGraphicsDevice.CreateDrawingSurface( new Windows.Foundation.Size(rectWidth, rectHeight), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); // Draw to surface and create surface brush. var noiseFilePath = AppDomain.CurrentDomain.BaseDirectory + "Assets\\NoiseAsset_256X256.png"; LoadSurface(noiseDrawingSurface, noiseFilePath); noiseSurfaceBrush = compositor.CreateSurfaceBrush(noiseDrawingSurface); // Add composition content to tree. AddCompositionContent(); }
private void CompositionHostControl_Loaded(object sender, RoutedEventArgs e) { _currentDpi = WindowsMedia.VisualTreeHelper.GetDpi(this); _rectWidth = CompositionHostElement.ActualWidth / 2; _rectHeight = CompositionHostElement.ActualHeight / 2; // Get graphics device. _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); // Create surface. var noiseDrawingSurface = _compositionGraphicsDevice.CreateDrawingSurface( new Windows.Foundation.Size(_rectWidth, _rectHeight), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); // Draw to surface and create surface brush. var noiseFilePath = AppDomain.CurrentDomain.BaseDirectory + "Assets\\NoiseAsset_256X256.png"; LoadSurface(noiseDrawingSurface, noiseFilePath); _noiseSurfaceBrush = _compositor.CreateSurfaceBrush(noiseDrawingSurface); // Add composition content to tree. _compositionHost.SetChild(_containerVisual); AddCompositionContent(); ToggleAcrylic(); }
private static async Task <CompositionDrawingSurface> GetCompositionDrawingSurface(Compositor compositor, RenderTargetBitmap renderTargetBitmap) { IBuffer pixels = await renderTargetBitmap.GetPixelsAsync(); using (var canvasDevice = new CanvasDevice()) using (CompositionGraphicsDevice graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice)) { float dpi = DisplayInformation.GetForCurrentView().LogicalDpi; using (var canvasBitmap = CanvasBitmap.CreateFromBytes(canvasDevice, pixels.ToArray(), renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight, DirectXPixelFormat.B8G8R8A8UIntNormalized, dpi)) { CompositionDrawingSurface surface = graphicsDevice.CreateDrawingSurface( new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface)) { session.DrawImage(canvasBitmap, 0, 0, new Rect(0, 0, canvasBitmap.Size.Width, canvasBitmap.Size.Height)); } return(surface); } } }
protected override void OnDisconnected() { if (CompositionBrush != null) { IsConnected = false; canvasDevice.Dispose(); canvasDevice = null; graphicsDevice.Dispose(); graphicsDevice = null; surfaceBrush1.Dispose(); surfaceBrush1 = null; surfaceBrush2.Dispose(); surfaceBrush2 = null; surface1.Dispose(); surface1 = null; surface2.Dispose(); surface2 = null; Source1Animation.Dispose(); Source1Animation = null; Source2Animation.Dispose(); Source2Animation = null; colorBrush1.Dispose(); colorBrush1 = null; colorBrush2.Dispose(); colorBrush2 = null; CompositionBrush.Dispose(); CompositionBrush = null; } }
/// <summary> /// Handles the RenderingDeviceReplaced event /// </summary> /// <param name="sender">CompositionGraphicsDevice</param> /// <param name="args">RenderingDeviceReplacedEventArgs</param> private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { if (DeviceReplaced != null) { RaiseDeviceReplacedEvent(); } }
public Screenshot() { _canvasDevice = new CanvasDevice(); _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice( Window.Current.Compositor, _canvasDevice); _compositor = Window.Current.Compositor; _surface = _compositionGraphicsDevice.CreateDrawingSurface( new Size(400, 400), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); // This is the only value that currently works with // the composition APIs. //var visual = _compositor.CreateSpriteVisual(); //visual.RelativeSizeAdjustment = Vector2.One; //var brush = _compositor.CreateSurfaceBrush(_surface); //brush.HorizontalAlignmentRatio = 0.5f; //brush.VerticalAlignmentRatio = 0.5f; //brush.Stretch = CompositionStretch.Uniform; //visual.Brush = brush; //ElementCompositionPreview.SetElementChildVisual(this, visual); }
public CompositionMaskHelper(Compositor compositor) { _compositor = compositor; _canvasDevice = new CanvasDevice(); _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _surfaceFactory = SurfaceFactory.CreateFromCompositor(_compositor); }
/// <summary> /// Constructor /// </summary> /// <param name="compositor">Compositor</param> /// <param name="useSharedCanvasDevice">Whether to use a shared CanvasDevice or to create a new one.</param> /// <param name="useSoftwareRenderer">Whether to use Software Renderer when creating a new CanvasDevice.</param> public CompositionGenerator(Compositor compositor, bool useSharedCanvasDevice = true, bool useSoftwareRenderer = false) { if (compositor == null) { throw new ArgumentNullException(nameof(compositor), "Compositor cannot be null!"); } // Compositor _compositor = compositor; // Disposing Lock _disposingLock = new object(); // Canvas Device _canvasDevice = useSharedCanvasDevice ? CanvasDevice.GetSharedDevice() : new CanvasDevice(useSoftwareRenderer); _isCanvasDeviceCreator = !useSharedCanvasDevice; _canvasDevice.DeviceLost += DeviceLost; // Composition Graphics Device _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _isGraphicsDeviceCreator = true; _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; if (!DesignMode.DesignModeEnabled) { DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated; } }
/// <summary> /// Deconstructs the Composition Brush. /// </summary> protected override void OnDisconnected() { base.OnDisconnected(); if (_device != null) { _device.DeviceLost -= CanvasDevice_DeviceLost; _device = null; } if (_graphics != null) { _graphics.RenderingDeviceReplaced -= CanvasDevice_RenderingDeviceReplaced; _graphics = null; } // Dispose of composition resources when no longer in use. if (CompositionBrush != null) { CompositionBrush.Dispose(); CompositionBrush = null; } if (_surfaceBrush != null) { _surfaceBrush.Dispose(); _surfaceBrush = null; } }
public void Dispose() { lock (_drawingLock) { _compositor = null; DisplayInformation.DisplayContentsInvalidated -= OnDisplayContentsInvalidated; if (_canvasDevice != null) { _canvasDevice.DeviceLost -= DeviceLost; // // Only dispose the canvas device if we own the device. // if (_isDeviceCreator) { _canvasDevice.Dispose(); } _canvasDevice = null; } if (_graphicsDevice != null) { _graphicsDevice.RenderingDeviceReplaced -= RenderingDeviceReplaced; // // Only dispose the composition graphics device if we own the device. // if (_isDeviceCreator) { _graphicsDevice.Dispose(); } _graphicsDevice = null; } } }
/// <summary> /// Constructor /// </summary> /// <param name="compositor">Compositor</param> /// <param name="graphicsDevice">CompositionGraphicsDevice</param> /// <param name="sharedLock">shared lock</param> public CompositionMaskGenerator(Compositor compositor, CompositionGraphicsDevice graphicsDevice = null, object sharedLock = null) { if (compositor == null) { throw new ArgumentNullException(nameof(compositor), "Compositor cannot be null!"); } _compositor = compositor; _drawingLock = sharedLock ?? new object(); if (_canvasDevice == null) { _canvasDevice = CanvasDevice.GetSharedDevice(); _canvasDevice.DeviceLost += DeviceLost; } if (graphicsDevice == null) { // Create the Composition Graphics Device _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _isDeviceCreator = true; } else { _graphicsDevice = graphicsDevice; _isDeviceCreator = false; } // Subscribe to events _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated; }
internal void InitializeComposition() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _win2DDevice = CanvasDevice.GetSharedDevice(); _comositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _win2DDevice); _myDrawingVisual = _compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(this, _myDrawingVisual); }
public void InitializeComposition() { compositor = ElementCompositionPreview.GetElementVisual(this as UIElement).Compositor; win2dDevice = CanvasDevice.GetSharedDevice(); comositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, win2dDevice); myDrawingVisual = compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(virtualSurfaceHost, myDrawingVisual); }
private void BubbleView_Unloaded(object sender, RoutedEventArgs e) { ClearBubbles(); _BubblesVisual?.Dispose(); _BubblesVisual = null; _canvasDevice = null; _graphicsDevice?.Dispose(); _graphicsDevice = null; }
public DrawingSurfaceRenderer(Compositor compositor, CompositionGraphicsDevice compositionGraphicsDevice) { drawingSurfaceVisual = compositor.CreateSpriteVisual(); drawingSurface = compositionGraphicsDevice.CreateDrawingSurface(new Size(256, 256), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); drawingSurfaceVisual.Brush = compositor.CreateSurfaceBrush(drawingSurface); DrawDrawingSurface(); compositionGraphicsDevice.RenderingDeviceReplaced += CompositionGraphicsDevice_RenderingDeviceReplaced; }
private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { Task.Run(() => { if (_deviceReplacedEvent != null) { RaiseDeviceReplacedEvent(); } }); }
public DrawingSurfaceRenderer(Compositor compositor, CompositionGraphicsDevice compositionGraphicsDevice) { drawingSurfaceVisual = compositor.CreateSpriteVisual(); drawingSurface = compositionGraphicsDevice.CreateDrawingSurface(new Size(256, 256), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); drawingSurfaceVisual.Brush = compositor.CreateSurfaceBrush(drawingSurface); DrawDrawingSurface(); compositionGraphicsDevice.RenderingDeviceReplaced += CompositionGraphicsDevice_RenderingDeviceReplaced; }
//初始化CanvasDevice和GraphicsDevice private void SetupDevices() { DisplayInformation.DisplayContentsInvalidated += DisplayInformation_DisplayContentsInvalidated; _canvasDevice = CanvasDevice.GetSharedDevice(); _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_Compositor, _canvasDevice); _canvasDevice.DeviceLost += _canvasDevice_DeviceLost; _graphicsDevice.RenderingDeviceReplaced += _graphicsDevice_RenderingDeviceReplaced; }
static public void Initialize(Compositor compositor) { Debug.Assert(!_intialized); _compositor = compositor; _canvasDevice = new CanvasDevice(); _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _intialized = true; }
static public void Initialize(Compositor compositor) { Debug.Assert(!_intialized); _compositor = compositor; _canvasDevice = new CanvasDevice(); _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _intialized = true; }
public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size) { var canvasDevice = CanvasComposition.GetCanvasDevice(device); CanvasBitmap canvasBitmap; if (_softwareBitmap != null) { canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(canvasDevice, _softwareBitmap); } else if (_file != null) { SoftwareBitmap softwareBitmap = await LoadFromFile(_file); canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(canvasDevice, softwareBitmap); } else { canvasBitmap = await CanvasBitmap.LoadAsync(canvasDevice, _uri); } var bitmapSize = canvasBitmap.Size; // // Because the drawing is done asynchronously and multiple threads could // be trying to get access to the device/surface at the same time, we need // to do any device/surface work under a lock. // lock (drawingLock) { Size surfaceSize = size; if (surface.Size != size || surface.Size == new Size(0, 0)) { // Resize the surface to the size of the image CanvasComposition.Resize(surface, bitmapSize); surfaceSize = bitmapSize; } // Allow the app to process the bitmap if requested if (_handler != null) { _handler(surface, canvasBitmap, device); } else { // Draw the image to the surface using (var session = CanvasComposition.CreateDrawingSession(surface)) { session.Clear(Windows.UI.Color.FromArgb(0, 0, 0, 0)); session.DrawImage(canvasBitmap, new Rect(0, 0, surfaceSize.Width, surfaceSize.Height), new Rect(0, 0, bitmapSize.Width, bitmapSize.Height)); } } } }
public void Initialize(CompositionGraphicsDevice graphicsDevice) { _graphicsDevice = graphicsDevice; _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; _drawingLock = new object(); _isDeviceCreator = false; // // We don't call CreateDevice, as it wouldn't do anything // since we don't have a Compositor. // }
static public void Initialize(Compositor compositor) { if (!IsInitialized) { _compositor = compositor; _canvasDevice = new CanvasDevice(); _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); IsInitialized = true; } }
public void Initialize(CompositionGraphicsDevice graphicsDevice) { _graphicsDevice = graphicsDevice; _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; _drawingLock = new object(); _isDeviceCreator = false; // // We don't call CreateDevice, as it wouldn't do anything // since we don't have a Compositor. // }
private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { Debug.WriteLine("CompositionImageLoader - Rendering Device Replaced"); Task.Run(() => { if (DeviceReplacedEvent != null) { RaiseDeviceReplacedEvent(); } }); }
static public void Uninitialize() { _compositor = null; if (_compositionDevice != null) { _compositionDevice.Dispose(); _compositionDevice = null; } if (_canvasDevice != null) { _canvasDevice.Dispose(); _canvasDevice = null; } _intialized = false; }
public async Task Create(CompositionGraphicsDevice device) { _random = new Random(); _device = device; _allUris = new List<Uri>(); StorageFolder useFolder = await GetPhotosFolder(); await AddFiles(useFolder); // Ensure that each file is only listed once for (int a = 0; a < _allUris.Count - 1; a++) { for (int b = a + 1; b < _allUris.Count; b++) { if (String.Equals( _allUris[a].LocalPath, _allUris[b].LocalPath, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allUris.Count]; int index = 0; foreach (var uri in _allUris) { _allPhotos[index++] = new Photo(uri, _device); } // Rather than continously picking random photos, we want to shuffle all photos to // ensure that we don't unnecessarily duplicate photos. Otherwise, statistically, we // will have more duplicated photos than necessary, and not even load some photos. ShufflePhotos(); }
public async Task Create(CompositionGraphicsDevice device) { _random = new Random(); _device = device; _allUris = new List<Uri>(); // Search pictures to build Uri collection of images. StorageFolder picturesFolder = KnownFolders.PicturesLibrary; StorageFolder useFolder = picturesFolder; try { var item = await picturesFolder.TryGetItemAsync("Demo"); if ((item != null) && item.IsOfType(StorageItemTypes.Folder)) { StorageFolder demosFolder = (StorageFolder)item; useFolder = demosFolder; } } catch (Exception) { } await AddFiles(useFolder); // Ensure that each file is only listed once for (int a = 0; a < _allUris.Count - 1; a++) { for (int b = a + 1; b < _allUris.Count; b++) { if (String.Equals( _allUris[a].LocalPath, _allUris[b].LocalPath, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allUris.Count]; int index = 0; foreach (var uri in _allUris) { _allPhotos[index++] = new Photo(uri, _device); } // Rather than continously picking random photos, we want to shuffle all photos to // ensure that we don't unnecessarily duplicate photos. Otherwise, statistically, we // will have more duplicated photos than necessary, and not even load some photos. ShufflePhotos(); }
/// <summary> /// Constructor /// </summary> /// <param name="compositor">Compositor</param> /// <param name="useSharedCanvasDevice">Whether to use a shared CanvasDevice or to create a new one.</param> /// <param name="useSoftwareRenderer">Whether to use Software Renderer when creating a new CanvasDevice.</param> public CompositionGenerator(Compositor compositor, bool useSharedCanvasDevice = true, bool useSoftwareRenderer = false) { if (compositor == null) throw new ArgumentNullException(nameof(compositor), "Compositor cannot be null!"); // Compositor _compositor = compositor; // Disposing Lock _disposingLock = new object(); // Canvas Device _canvasDevice = useSharedCanvasDevice ? CanvasDevice.GetSharedDevice() : new CanvasDevice(useSoftwareRenderer); _isCanvasDeviceCreator = !useSharedCanvasDevice; _canvasDevice.DeviceLost += DeviceLost; // Composition Graphics Device _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _isGraphicsDeviceCreator = true; _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; if (!DesignMode.DesignModeEnabled) DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated; }
private CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget) { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 10.0f, BorderMode = EffectBorderMode.Hard, }; float fDownsample = .3f; Size sizeSource = bitmap.Size; if (sizeTarget == Size.Empty) { sizeTarget = sizeSource; } sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample); CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(blurSurface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height)); ds.FillRectangle(destination, Windows.UI.Color.FromArgb(60, 0, 0, 0)); } return blurSurface; }
public Photo(Uri uri, CompositionGraphicsDevice device) { _uri = uri; _device = device; }
void CompositionGraphicsDevice_RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { DrawDrawingSurface(); }
private CompositionDrawingSurface SampleImageColor(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget) { // Extract the color to tint the blur with Color predominantColor = ExtractPredominantColor(bitmap.GetPixelColors(), bitmap.Size); Size sizeSource = bitmap.Size; if (sizeTarget.IsEmpty) { sizeTarget = sizeSource; } // Create a heavily blurred version of the image GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Source = bitmap, BlurAmount = 20.0f }; CompositionDrawingSurface surface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(surface)) { Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height); ds.FillRectangle(destination, predominantColor); ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height), .6f); } return surface; }
/// <summary> /// Instantiates a CompositionGenerator object /// </summary> /// <param name="graphicsDevice">Composition Graphics Device</param> /// <returns>ICompositionGenerator</returns> public static ICompositionGenerator GetCompositionGenerator(CompositionGraphicsDevice graphicsDevice) { return new CompositionGenerator(graphicsDevice); }
private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { Debug.WriteLine("CompositionImageLoader - Rendering Device Replaced"); Task.Run(() => { if (DeviceReplacedEvent != null) { RaiseDeviceReplacedEvent(); } }); }
private void CreateDevice() { if (_compositor != null) { if (_canvasDevice == null) { _canvasDevice = new CanvasDevice(); _canvasDevice.DeviceLost += DeviceLost; } if (_graphicsDevice == null) { _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice); _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; } } }
private static async Task<CompositionDrawingSurface> LoadFromUri(CanvasDevice canvasDevice, CompositionGraphicsDevice compositionDevice, Uri uri, Size sizeTarget) { CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(canvasDevice, uri); Size sizeSource = bitmap.Size; if (sizeTarget.IsEmpty) { sizeTarget = sizeSource; } var surface = compositionDevice.CreateDrawingSurface( sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); using (var ds = CanvasComposition.CreateDrawingSession(surface)) { ds.Clear(Color.FromArgb(0, 0, 0, 0)); ds.DrawImage( bitmap, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), new Rect(0, 0, sizeSource.Width, sizeSource.Height), 1, CanvasImageInterpolation.HighQualityCubic); } return surface; }
void CreateDevice() { device = CanvasDevice.GetSharedDevice(); device.DeviceLost += Device_DeviceLost; if (compositionGraphicsDevice == null) { compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, device); } else { CanvasComposition.SetCanvasDevice(compositionGraphicsDevice, device); } if (swapChainRenderer != null) swapChainRenderer.SetDevice(device, new Size(window.Bounds.Width, window.Bounds.Height)); }
public void Dispose() { lock (_drawingLock) { _compositor = null; DisplayInformation.DisplayContentsInvalidated -= OnDisplayContentsInvalidated; if (_canvasDevice != null) { _canvasDevice.DeviceLost -= DeviceLost; // // Only dispose the canvas device if we own the device. // if (_isDeviceCreator) { _canvasDevice.Dispose(); } _canvasDevice = null; } if (_graphicsDevice != null) { _graphicsDevice.RenderingDeviceReplaced -= RenderingDeviceReplaced; // // Only dispose the composition graphics device if we own the device. // if (_isDeviceCreator) { _graphicsDevice.Dispose(); } _graphicsDevice = null; } } }
/// <summary> /// Constructor /// </summary> /// <param name="graphicsDevice">Composition Graphics Device</param> public CompositionGenerator(CompositionGraphicsDevice graphicsDevice) { if (graphicsDevice == null) throw new ArgumentNullException(nameof(graphicsDevice), "GraphicsDevice cannot be null!"); // Composition Graphics Device _graphicsDevice = graphicsDevice; _isGraphicsDeviceCreator = false; _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced; if (!DesignMode.DesignModeEnabled) DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated; // Compositor _compositor = _graphicsDevice.Compositor; // Canvas Device _canvasDevice = CanvasComposition.GetCanvasDevice(_graphicsDevice); _isCanvasDeviceCreator = false; _canvasDevice.DeviceLost += DeviceLost; }
/// <summary> /// Handles the RenderingDeviceReplaced event /// </summary> /// <param name="sender">CompositionGraphicsDevice</param> /// <param name="args">RenderingDeviceReplacedEventArgs</param> private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args) { RaiseDeviceReplacedEvent(); }
public static IImageLoader CreateImageLoader(CompositionGraphicsDevice graphicsDevice) { var imageLoader = new ImageLoader(); imageLoader.Initialize(graphicsDevice); return imageLoader; }