/// <summary> /// Generates a blended image with a CAM and the desired overlay color /// </summary> /// <returns>The blended CAMI mage.</returns> /// <param name="index">Index.</param> /// <param name="color">Color.</param> private async Task <UIImage> GenerateBlendedCAMImage(CAM cam, SKColor color) { // Cancel the previous blending task if there is one cancellationTokenSource?.Cancel(); cancellationTokenSource = new CancellationTokenSource(); // Dispose of previous blended image blendedImage?.Dispose(); SKBitmap colorMap = await ImageProcessorRunner.GetCAMColorMapTask( cam, color, (int)(InputImage.Size.Width *InputImage.CurrentScale), (int)(InputImage.Size.Height *InputImage.CurrentScale), cancellationTokenSource.Token ); SKBitmap input = InputImage.ToSKBitmap(); SKBitmap blendedSKBitmap = await ImageProcessorRunner.GetOverlayImageTask( input, colorMap, cancellationTokenSource.Token ); // Dispose of temporary SKBitmap input.Dispose(); UIImage blendedUIImage = blendedSKBitmap.ToUIImage(); // Cleanup the intermediate bitmaps colorMap?.Dispose(); blendedSKBitmap?.Dispose(); return(blendedUIImage); }