protected override async void OnNavigatedTo(NavigationEventArgs e) { _rootVisual = GetVisual(PictureHost); _compositor = _rootVisual.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); _rootVisual.Clip = _compositor.CreateInsetClip(0, 0, 0, 0); // Begin the TransitionController to load images and kick off animations. try { _transitionController = new TransitionController(); await _transitionController.Create(_rootVisual, _imageFactory); var actualSize = new Vector2((float)PictureHost.ActualWidth, (float)PictureHost.ActualHeight); _transitionController.UpdateWindowSize(actualSize); NearSlideCheckBox_Click(this, null); FarSlideCheckBox_Click(this, null); FlashlightCheckBox_Click(this, null); ZoomCheckBox_Click(this, null); StackCheckBox_Click(this, null); _transitionController.NextTransition(); } catch { } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize Composition UI infrastructure. _root = Container.GetVisual(); _compositor = _root.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // Hook the sprite visual into the XAML visual tree. _spriteVisual = _compositor.CreateSpriteVisual(); var side = (float)Math.Min(Presenter.ActualWidth, Presenter.ActualHeight); _spriteVisual.Size = new Vector2(side, side); _root.Children.InsertAtTop(_spriteVisual); // Create the effect, but don't specify the properties yet. var temperatureAndTintEffect = new TemperatureAndTintEffect { Name = "temperatureAndtint", Source = new CompositionEffectSourceParameter("source") }; // Strongly typed version of the "temperatureAndtint.Temperature" string _temperatureParameter = temperatureAndTintEffect.Name + "." + nameof(temperatureAndTintEffect.Temperature); // Compile the effect var effectFactory = _compositor.CreateEffectFactory( temperatureAndTintEffect, new[] { _temperatureParameter, "temperatureAndtint.Tint" }); // Create and apply the brush. _brush = effectFactory.CreateBrush(); _spriteVisual.Brush = _brush; ColorWheelButton.IsChecked = true; }
private async void PictureHost_Loaded(object sender, RoutedEventArgs e) { // Host the Composition scene inside the PictureHost canvas, allowing us to also display // Xaml controls. _rootVisual = GetVisual(PictureHost); _compositor = _rootVisual.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); _rootVisual.Clip = _compositor.CreateInsetClip(0, 0, 0, 0); // Begin the TransitionController to load images and kick off animations. _transitionController = new TransitionController(); await _transitionController.Create(_rootVisual, _imageFactory); var actualSize = new Vector2((float)PictureHost.ActualWidth, (float)PictureHost.ActualHeight); _transitionController.UpdateWindowSize(actualSize); NearSlideCheckBox_Click(this, null); FarSlideCheckBox_Click(this, null); FlashlightCheckBox_Click(this, null); ZoomCheckBox_Click(this, null); StackCheckBox_Click(this, null); _transitionController.NextTransition(); }
void CreateChildElement() { Uri localUri = new Uri("ms-appx:///Assets/StoreLogo.png"); _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); CompositionImageOptions options = new CompositionImageOptions() { DecodeWidth = 400, DecodeHeight = 400, }; _image = _imageFactory.CreateImageFromUri(localUri, options); var visual = _compositor.CreateSpriteVisual(); visual.Size = new Vector2(400.0f, 400.0f); visual.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _root.Children.InsertAtTop(visual); // If for some reason the image fails to load, replace the brush with // a red solid color. _image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) => { if (status != CompositionImageLoadStatus.Success) { visual.Brush = _compositor.CreateColorBrush(Colors.Red); } }; }
public void SetWindow(CoreWindow window) { Compositor compositor = new Compositor(); ContainerVisual root = compositor.CreateContainerVisual(); m_target = compositor.CreateTargetForCurrentView(); m_target.Root = root; Uri localUri = new Uri("ms-appx:///Assets/StoreLogo.png"); var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor); CompositionImageOptions options = new CompositionImageOptions() { DecodeWidth = 400, DecodeHeight = 400, }; var image = imageFactory.CreateImageFromUri(localUri, options); var visual = compositor.CreateSpriteVisual(); visual.Size = new Vector2(400.0f, 400.0f); visual.Brush = compositor.CreateSurfaceBrush(image.Surface); root.Children.InsertAtTop(visual); image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) => { if (status != CompositionImageLoadStatus.Success) { visual.Brush = compositor.CreateColorBrush(Colors.Red); } }; }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize Composition UI infrastructure. _root = Container.GetVisual(); _compositor = _root.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // Hook the sprite visual into the XAML visual tree. _spriteVisual = _compositor.CreateSpriteVisual(); var side = (float)Math.Min(Presenter.ActualWidth, Presenter.ActualHeight); _spriteVisual.Size = new Vector2(side, side); _root.Children.InsertAtTop(_spriteVisual); // Create the effect, but don't specify the Angle yet. var hueRotationEffect = new HueRotationEffect { Name = "hueRotation", Source = new CompositionEffectSourceParameter("source") }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(hueRotationEffect, new[] { "hueRotation.Angle" }); // Create and apply the brush. _brush = effectFactory.CreateBrush(); _spriteVisual.Brush = _brush; ColorWheelButton.IsChecked = true; }
void InitNewComposition() { // // Set up Windows.UI.Composition Compositor, root ContainerVisual, and associate with // the CoreWindow. // _compositor = new Compositor(); _root = _compositor.CreateContainerVisual(); _target = _compositor.CreateTargetForCurrentView(); _target.Root = _root; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); Desaturate(); }
ScalarKeyFrameAnimation imageFlipAnimation, textFlipAnimation; //MediaTransport Image, Textbox animations void setupAnimations() { visual = ElementCompositionPreview.GetElementVisual(this); compositor = visual.Compositor; blurredVisual = compositor.CreateSpriteVisual(); imageFactory = CompositionImageFactory.CreateCompositionImageFactory(compositor); var graphicsEffect = new BlendEffect { Mode = BlendEffectMode.HardLight, Background = new ColorSourceEffect() { Name = "Tint", Color = Color.FromArgb(200, 0, 0, 0), }, Foreground = new GaussianBlurEffect() { Name = "Blur", Source = new CompositionEffectSourceParameter("source"), BlurAmount = 20.0f, Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount", "Tint.Color" }); fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation(); fadeOutAnimation.InsertExpressionKeyFrame(0.0f, "1"); fadeOutAnimation.InsertExpressionKeyFrame(1f, "0"); fadeOutAnimation.Duration = TimeSpan.FromMilliseconds(500); fadeInAnimation = compositor.CreateScalarKeyFrameAnimation(); fadeInAnimation.InsertExpressionKeyFrame(0.0f, "0"); fadeInAnimation.InsertExpressionKeyFrame(1f, "1"); fadeInAnimation.Duration = TimeSpan.FromMilliseconds(500); imageFlipAnimation = compositor.CreateScalarKeyFrameAnimation(); imageFlipAnimation.InsertExpressionKeyFrame(0.0f, "-60"); imageFlipAnimation.InsertExpressionKeyFrame(1f, "0"); imageFlipAnimation.Duration = TimeSpan.FromMilliseconds(500); textFlipAnimation = compositor.CreateScalarKeyFrameAnimation(); textFlipAnimation.InsertExpressionKeyFrame(0.0f, "-90"); textFlipAnimation.InsertExpressionKeyFrame(1f, "0"); textFlipAnimation.Duration = TimeSpan.FromMilliseconds(300); }
private void Clock_Loaded(object sender, RoutedEventArgs e) { _root = Container.GetVisual(); _compositor = _root.Compositor; // Background _background = _compositor.CreateSpriteVisual(); _background.Size = new Vector2(800.0f, 800.0f); var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); var options = new CompositionImageOptions() { DecodeWidth = 740, DecodeHeight = 740 }; var _image = _imageFactory.CreateImageFromUri(FaceImage, options); _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _root.Children.InsertAtTop(_background); // Hour Hand _hourhand = _compositor.CreateSpriteVisual(); _hourhand.Size = new Vector2(800.0f, 800.0f); _image = _imageFactory.CreateImageFromUri(HourHandImage, options); _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _hourhand.Offset = new Vector3(0.0f, 0.0f, 0); _hourhand.CenterPoint = new Vector3(400.0f, 400.0f, 0); _root.Children.InsertAtTop(_hourhand); // Minute Hand _minutehand = _compositor.CreateSpriteVisual(); _minutehand.Size = new Vector2(800.0f, 800.0f); _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options); _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _minutehand.Offset = new Vector3(0.0f, 0.0f, 0); _minutehand.CenterPoint = new Vector3(400.0f, 400.0f, 0); _root.Children.InsertAtTop(_minutehand); // Foreground _foreground = _compositor.CreateSpriteVisual(); _foreground.Size = new Vector2(800.0f, 800.0f); _image = _imageFactory.CreateImageFromUri(FrontImage, options); _foreground.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _root.Children.InsertAtTop(_foreground); SetHoursAndMinutes(); _timer.Start(); }
void LayoutRoot_Loaded(object sender, RoutedEventArgs e) { // get visuals from xaml object _touchAreaVisual = GetVisual(this.TouchArea); var imagePanelVisual = GetVisual(this.ImagePanel); // get compositor _compositor = imagePanelVisual.Compositor; var width = (float)this.ImagePanel.ActualWidth; var height = (float)this.ImagePanel.ActualHeight; // load the background image var uri = new Uri("ms-appx:///Assets/White.png"); var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); var options = new CompositionImageOptions { DecodeWidth = (int)width, DecodeHeight = (int)height }; var image = imageFactory.CreateImageFromUri(uri, options); // currently GaussianBlurEffect is not supported in Composition var effectDefination = new SaturationEffect // new GaussianBlurEffect { //BorderMode = EffectBorderMode.Soft, //BlurAmount = 5f, //Optimization = EffectOptimization.Quality, Source = new CompositionEffectSourceParameter("Overlay") }; // create the actual effect var surfaceBrush = _compositor.CreateSurfaceBrush(image.Surface); var effectFactory = _compositor.CreateEffectFactory(effectDefination); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("Overlay", surfaceBrush); // create the visual with the effect _visual = _compositor.CreateSpriteVisual(); _visual.Brush = effectBrush; _visual.Opacity = 0.8f; _visual.Size = new Vector2(width, height); // place the effect visual onto the UI imagePanelVisual.Children.InsertAtTop(_visual); }
/// <summary> /// MainPage_Loaded is used for all of our initialization to keep the UI thread mostly free. /// </summary> /// <param name="sender">not used</param> /// <param name="e">not used</param> private void MainPage_Loaded(object sender, RoutedEventArgs e) { _compositor = ElementCompositionPreview.GetElementVisual(sender as UIElement).Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(Scroller); SurfaceLoader.Initialize(_compositor); ParallaxingImage.LoadTimeEffectHandler = ApplyBlurEffect; ParallaxingImage.Uri = new Uri("ms-appx:///assets/RollingWaves.jpg"); ParallaxingImage.SetEffectBrush(InitializeCrossFadeEffect()); var maskedBrush = InitializeCompositeEffect(); ParallaxingImage.SizeChanged += (s, ev) => { UpdateSizes(); }; InitializeBackgroundImageVisual(scrollProperties); InitializeFrontVisual(scrollProperties, maskedBrush); InitializeBehindVisual(scrollProperties, maskedBrush); UpdateSizes(); }
/// <summary> /// Bind Compositon Images to the list which need to continue to the next page on navigation. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void FruitsList_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { //Get the clicked Item var item = args.Item as Item; //Get hold of the UIElement to bind items. var contentPanel = args.ItemContainer.ContentTemplateRoot as StackPanel; //Create Composition Image from data source var parentRectangle = _compositor.CreateContainerVisual(); var rectangleColor = _compositor.CreateSpriteVisual(); rectangleColor.Size = new System.Numerics.Vector2(40, 40); //Use ImageFactory to load image from URI. try { CompositionImageFactory imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); CompositionImageOptions options = new CompositionImageOptions() { DecodeWidth = 160, DecodeHeight = 160, }; CompositionImage image = imageFactory.CreateImageFromUri(item.imageUri, options); rectangleColor.Brush = _compositor.CreateSurfaceBrush(image.Surface); } catch { rectangleColor.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Red); } //Bind Composition Image to UIElement - Rectangle in this case. Rectangle rectImage = contentPanel.FindName("imageItem") as Rectangle; parentRectangle.Children.InsertAtTop(rectangleColor); item.imageContainerVisual = parentRectangle; item.rectImage = rectImage; ElementCompositionPreview.SetElementChildVisual(rectImage, parentRectangle); }
private CompositionSurfaceBrush CreateBrushFromAsset(string name, out Size size) { Uri localUri = new Uri("ms-appx:///Assets/" + name); CompositionImageFactory surfaceFactory = CompositionImageFactory.CreateCompositionImageFactory(m_compositor); var image = surfaceFactory.CreateImageFromUri(localUri); bool isCompleted = false; var waitHandle = new AutoResetEvent(false); image.ImageLoaded += (CompositionImage sender, CompositionImageLoadStatus status) => { isCompleted = true; waitHandle.Set(); }; while (!isCompleted) { waitHandle.WaitOne(); } size = image.Size; return(m_compositor.CreateSurfaceBrush(image.Surface)); }
/// <summary> /// Initialize all Composition related stuff here (Compositor, Animations etc) /// </summary> private void InitializeComposition() { var rootVisual = ElementCompositionPreview.GetElementVisual(this); // Compositor _compositor = rootVisual.Compositor; // Final Value Expressions var vector3Expr = _compositor.CreateFinalValueExpression <Vector3>(); var scalarExpr = _compositor.CreateFinalValueExpression <float>(); // Opacity Animation var opacityAnimation = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(DefaultOpacityAnimationDuration) .ForTarget(() => rootVisual.Opacity); opacityAnimation.InsertExpressionKeyFrame(1f, scalarExpr); // Scale Animation var scaleAnimation = _compositor.CreateKeyFrameAnimation <Vector3>() .HavingDuration(DefaultScaleAnimationDuration) .ForTarget(() => rootVisual.Scale); scaleAnimation.InsertExpressionKeyFrame(1f, vector3Expr); // ImplicitAnimation _implicitAnimationCollection = _compositor.CreateImplicitAnimationCollection(); _implicitAnimationCollection["Opacity"] = opacityAnimation.Animation; _implicitAnimationCollection["Scale"] = scaleAnimation.Animation; // Expand Animations _expandLeftInset = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetAnimationDuration) .DelayBy(InsetAnimationDelayDuration); _expandLeftInset.InsertKeyFrame(1f, 0); _expandRightInset = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetAnimationDuration) .DelayBy(InsetAnimationDelayDuration); _expandInsetClip = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetClipAnimationDuration); _expandInsetClip.InsertKeyFrame(1f, 0); // Collapse Animations _collapseLeftInset = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetAnimationDuration); _collapseRightInset = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetAnimationDuration); _collapseInsetClip = _compositor.CreateKeyFrameAnimation <float>() .HavingDuration(InsetClipAnimationDuration); // Root Container _rootContainer = _compositor.CreateContainerVisual(); // Image Factory _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // If the ItemsSource has any items then create their corresponding images CreateImages(); }
public static CompositionImageFactory CreateCompositionImageFactory(Compositor compositor) { return(CompositionImageFactory.CreateCompositionImageFactory(compositor)); }
private void Clock_Loaded(object sender, RoutedEventArgs e) { _root = Container.GetVisual(); _compositor = _root.Compositor; // Background _background = _compositor.CreateSpriteVisual(); _background.Size = new Vector2(200.0f, 200.0f); var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); CompositionImageOptions options = new CompositionImageOptions() { DecodeWidth = 400, DecodeHeight = 400, }; var _image = _imageFactory.CreateImageFromUri(FaceImage, options); _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _root.Children.InsertAtTop(_background); // Hour Hand options = new CompositionImageOptions() { DecodeWidth = 72, DecodeHeight = 240, }; _hourhand = _compositor.CreateSpriteVisual(); _hourhand.Size = new Vector2(24.0f, 80.0f); _image = _imageFactory.CreateImageFromUri(HourHandImage, options); _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _hourhand.CenterPoint = new Vector3(12.0f, 70.0f, 0); _hourhand.Offset = new Vector3(88.0f, 30.0f, 0); _root.Children.InsertAtTop(_hourhand); // Minute Hand options = new CompositionImageOptions() { DecodeWidth = 48, DecodeHeight = 270, }; _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options); _minutehand = _compositor.CreateSpriteVisual(); _minutehand.Size = new Vector2(16.0f, 90.0f); _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface); _minutehand.CenterPoint = new Vector3(8.0f, 85.0f, 0); _minutehand.Offset = new Vector3(92.0f, 15.0f, 0); _root.Children.InsertAtTop(_minutehand); SetHoursAndMinutes(); // Second Hand _secondhand = _compositor.CreateSpriteVisual(); _secondhand.Size = new Vector2(1.0f, 90.0f); _secondhand.Brush = _compositor.CreateColorBrush(Colors.Red); _secondhand.CenterPoint = new Vector3(0.5f, 90.0f, 0); _secondhand.Offset = new Vector3(99.5f, 10.0f, 0); _root.Children.InsertAtTop(_secondhand); _secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6; _timer.Start(); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { // Initialize Composition UI infrastructure. _leftRoot = LeftContainer.GetVisual(); _middleRoot = MiddleContainer.GetVisual(); _rightRoot = RightContainer.GetVisual(); _compositor = _leftRoot.Compositor; _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor); // Hook the sprite visuals into the XAML visual tree. _leftSpriteVisual = _compositor.CreateSpriteVisual(); var side = (float)Math.Min(LeftPresenter.ActualWidth, LeftPresenter.ActualHeight); _leftSpriteVisual.Size = new Vector2(side, side); _leftRoot.Children.InsertAtTop(_leftSpriteVisual); _middleSpriteVisual = _compositor.CreateSpriteVisual(); side = (float)Math.Min(MiddlePresenter.ActualWidth, MiddlePresenter.ActualHeight); _middleSpriteVisual.Size = new Vector2(side, side); _middleRoot.Children.InsertAtTop(_middleSpriteVisual); _rightSpriteVisual = _compositor.CreateSpriteVisual(); side = (float)Math.Min(RightPresenter.ActualWidth, RightPresenter.ActualHeight); _rightSpriteVisual.Size = new Vector2(side, side); _rightRoot.Children.InsertAtTop(_rightSpriteVisual); // Create CompositionSurfaceBrush _imageBrush = _compositor.CreateSurfaceBrush(); // Create an image source to load var imageSource = _imageFactory.CreateImageFromUri(new Uri("ms-appx:///Assets/flowers.jpg")); _imageBrush.Surface = imageSource.Surface; // Create and apply the first effect. _firstEffect = new SaturationEffect { Name = "firstEffect", Source = new CompositionEffectSourceParameter("source") }; var firstEffectFactory = _compositor.CreateEffectFactory(_firstEffect, new[] { "firstEffect.Saturation" }); _effectBrush1 = firstEffectFactory.CreateBrush(); _leftSpriteVisual.Brush = _effectBrush1; // Create and apply the second effect. var secondEffect = new InvertEffect { Name = "secondEffect", Source = new CompositionEffectSourceParameter("source") }; var secondEffectFactory = _compositor.CreateEffectFactory(secondEffect); _effectBrush2 = secondEffectFactory.CreateBrush(); _middleSpriteVisual.Brush = _effectBrush2; // Create and apply the combined effect. _combinedEffect = new InvertEffect { Name = "chained", Source = _firstEffect }; var combinedEffectFactory = _compositor.CreateEffectFactory(_combinedEffect, new[] { "firstEffect.Saturation" }); _combinedBrush = combinedEffectFactory.CreateBrush(); _rightSpriteVisual.Brush = _combinedBrush; // Chain the brushes _effectBrush1.SetSourceParameter("source", _imageBrush); _effectBrush2.SetSourceParameter("source", _imageBrush); _combinedBrush.SetSourceParameter("source", _imageBrush); }