コード例 #1
0
        /// <summary>
        /// Helper class to redraw the IImageSurface asynchronously
        /// </summary>
        /// <returns>Task</returns>
        private async Task RedrawSurfaceAsync()
        {
            // Cache the canvasBitmap to avoid reloading of the same image during Resize/Redraw operations
            _canvasBitmap = await _generator.RedrawImageSurfaceAsync(_surfaceLock, _surface, _uri, Options, _canvasBitmap);

            // If AutoResize is allowed and the image is successfully loaded into the canvasBitmap,
            // then update the Size property of the surface as the surface has been resized to match the canvasBitmap size
            if (Options.AutoResize)
            {
                // If the image is successfully loaded into the canvasBitmap, then update the Size property
                // of the surface as the surface has been resized to match the canvasBitmap size
                Size = _canvasBitmap?.Size ?? new Size(0, 0);
            }

            Status = _canvasBitmap != null ? ImageSurfaceLoadStatus.Success : ImageSurfaceLoadStatus.Error;

            // Get the canvasbitmap dimensions
            if (_canvasBitmap != null)
            {
                DecodedPhysicalSize = new Size(_canvasBitmap.SizeInPixels.Width, _canvasBitmap.SizeInPixels.Height);
                DecodedSize         = _canvasBitmap.Size;
            }
            // Raise the event
            if (_raiseLoadCompletedEvent)
            {
                LoadCompleted?.Invoke(this, Status);
                _raiseLoadCompletedEvent = false;
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="generator">ICompositionMaskGeneratorInternal object</param>
 /// <param name="uri">Uri of the image to be loaded onto the IImageSurface.</param>
 /// <param name="size">Size of the IImageSurface</param>
 /// <param name="options">The image's resize and alignment options in the allocated space.</param>
 public ImageSurface(ICompositionGeneratorInternal generator, Uri uri, Size size, ImageSurfaceOptions options)
 {
     _generator   = generator ?? throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!");
     _surfaceLock = new object();
     // Create the Surface of the IImageSurface
     _surface = _generator.CreateDrawingSurface(_surfaceLock, size);
     Size     = _surface?.Size ?? new Size(0, 0);
     _uri     = uri;
     _raiseLoadCompletedEvent = _uri != null;
     _canvasBitmap            = null;
     // Set the image options
     Options = options;
     // Subscribe to DeviceReplaced event
     _generator.DeviceReplaced += OnDeviceReplaced;
     Status = ImageSurfaceLoadStatus.None;
 }
コード例 #3
0
        /// <summary>
        /// Helper class to redraw the IImageSurface synchronously
        /// </summary>
        private void RedrawSurface()
        {
            // Resize the surface image
            _generator.RedrawImageSurface(_surfaceLock, _surface, Options, _canvasBitmap);
            // If AutoResize is allowed and the image is successfully loaded into the canvasBitmap,
            // then update the Size property of the surface as the surface has been resized to match the canvasBitmap size
            if (Options.AutoResize)
            {
                // If the image is successfully loaded into the canvasBitmap, then update the Size property
                // of the surface as the surface has been resized to match the canvasBitmap size
                Size = _canvasBitmap?.Size ?? new Size(0, 0);
            }

            Status = _canvasBitmap != null ? ImageSurfaceLoadStatus.Success : ImageSurfaceLoadStatus.Error;

            if (_canvasBitmap != null)
            {
                DecodedPhysicalSize = new Size(_canvasBitmap.SizeInPixels.Width, _canvasBitmap.SizeInPixels.Height);
                DecodedSize         = _canvasBitmap.Size;
            }
        }