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 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 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; }
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(); }
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 { } }
public async Task Create(ContainerVisual topContainer, CompositionImageFactory imageFactory) { _compositor = topContainer.Compositor; Tile.Initialize(_compositor); CommonAnimations.Initialize(_compositor); _layoutManager = new LayoutManager(); await _layoutManager.Create(topContainer, imageFactory); _transitionLibrary = new TransitionLibrary(_compositor, _layoutManager); _random = new Random(); NearSlideEntry = new TransitionEntry( TransitionKind.NearSlide, _layoutManager.GetNearNeighbor, _transitionLibrary.CreateNearSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.None); FarSlideEntry = new TransitionEntry( TransitionKind.FarSlide, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateFarSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.ColorFlashlight); ZoomEntry = new TransitionEntry( TransitionKind.Zoom, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateZoomAndPanTransition, TransitionOptions.Select, TransitionDesaturationMode.Regular); StackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateStackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); UnstackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateUnstackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); _entries = new TransitionEntry[] { NearSlideEntry, FarSlideEntry, ZoomEntry, StackEntry, UnstackEntry, }; }
public async Task Create(ContainerVisual topContainer, CompositionImageFactory imageFactory) { _compositor = topContainer.Compositor; Tile.Initialize(_compositor); CommonAnimations.Initialize(_compositor); _layoutManager = new LayoutManager(); await _layoutManager.Create(topContainer, imageFactory); _transitionLibrary = new TransitionLibrary(_compositor, _layoutManager); _random = new Random(); NearSlideEntry = new TransitionEntry( TransitionKind.NearSlide, _layoutManager.GetNearNeighbor, _transitionLibrary.CreateNearSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.None); FarSlideEntry = new TransitionEntry( TransitionKind.FarSlide, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateFarSlideTransition, TransitionOptions.Select, TransitionDesaturationMode.Regular); ZoomEntry = new TransitionEntry( TransitionKind.Zoom, _layoutManager.GetFarNeighbor, _transitionLibrary.CreateZoomAndPanTransition, TransitionOptions.Select, TransitionDesaturationMode.Regular); StackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateStackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); UnstackEntry = new TransitionEntry( TransitionKind.Stack, _layoutManager.GetCurrentPictureFrame, _transitionLibrary.CreateUnstackTransition, TransitionOptions.Select, TransitionDesaturationMode.None); _entries = new TransitionEntry[] { //NearSlideEntry, FarSlideEntry, //ZoomEntry, //StackEntry, //UnstackEntry, }; }
private void CreateImageFactory(UIElement element) { if (visual == null) { visual = GetVisual(element); } compositor = GetCompositor(visual); //visual.Clip = compositor.CreateInsetClip(0, 0, 0, 0); if (imageFactory == null) { imageFactory = CreateCompositionImageFactory(compositor); //<=== this causes a hige growth in memory footprint } }
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(); }
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(); }
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); }
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); }
public async Task Create(ContainerVisual rootContainer, CompositionImageFactory imageFactory) { // // Create a panning Visual that will be the entire size of all photos. // _rootContainer = rootContainer; _compositor = rootContainer.Compositor; _dispatcher = rootContainer.Dispatcher; _imageFactory = imageFactory; _panningContainer = _compositor.CreateContainerVisual(); _rootContainer.Children.InsertAtTop(_panningContainer); // // Configure the photo database and create the initial layout. // _random = new Random(); _allTiles = new List <Tile>(); _farTileHistory = new List <Tile>(); _nearTileHistory = new List <Tile>(); _photoDatabase = new PhotoDatabase(); await _photoDatabase.Create(_imageFactory); CreatePlaceholderLayout(); // // Start pictures loading: // - Don't load all of the pictures at once, as this will create threadpool threads for // each and will hammer the IO system, delaying everything. // - As each image arrives, connect it with a tile and start loading the next photo // until all tiles have photos. // for (int i = 0; i < ConcurrentDecodeThreads; i++) { LoadNextPhoto(); } }
public async Task Create(ContainerVisual rootContainer, CompositionImageFactory imageFactory) { // // Create a panning Visual that will be the entire size of all photos. // _rootContainer = rootContainer; _compositor = rootContainer.Compositor; _dispatcher = rootContainer.Dispatcher; _imageFactory = imageFactory; _panningContainer = _compositor.CreateContainerVisual(); _rootContainer.Children.InsertAtTop(_panningContainer); // // Configure the photo database and create the initial layout. // _random = new Random(); _allTiles = new List<Tile>(); _farTileHistory = new List<Tile>(); _nearTileHistory = new List<Tile>(); _photoDatabase = new PhotoDatabase(); await _photoDatabase.Create(_imageFactory); CreatePlaceholderLayout(); // // Start pictures loading: // - Don't load all of the pictures at once, as this will create threadpool threads for // each and will hammer the IO system, delaying everything. // - As each image arrives, connect it with a tile and start loading the next photo // until all tiles have photos. // for (int i = 0; i < ConcurrentDecodeThreads; i++) { LoadNextPhoto(); } }
public void Dispose() { imageFactory = null; imageSource = null; if (effect != null) { effect.Dispose(); effect = null; } if (surfaceBrush != null) { surfaceBrush.Surface = null; surfaceBrush.Dispose(); surfaceBrush = null; } //if (visual != null) //{ // if(spriteVisual!=null) visual.Children.Remove(spriteVisual); // visual.Dispose(); // visual = null; //} if (effectBrush != null) { effectBrush.SetSourceParameter(EffectSource, null); effectBrush.Dispose(); effectBrush = null; } if (spriteVisual != null) { spriteVisual.Brush = null; spriteVisual.Dispose(); spriteVisual = null; } }
/// <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); }
/// <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(); }
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)); }
//#region Detect Properties Change //private void DetectElementChange() //{ // frameworkElement.SizeChanged += (s, e) => // { // UpdateSpriteVisual(); // }; //} //#endregion private void CreateImageFactory(UIElement element) { visual = GetVisual(element); compositor = GetCompositor(visual); imageFactory = 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(); }
public Photo(StorageFile file, CompositionImageFactory imageFactory) { _file = file; _imageFactory = imageFactory; }
public async Task Create(CompositionImageFactory imageFactory) { _random = new Random(); _imageFactory = imageFactory; _allFiles = new List<StorageFile>(); // Search pictures to build File 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 < _allFiles.Count - 1; a++) { for (int b = a + 1; b < _allFiles.Count; b++) { if (String.Equals( _allFiles[a].Path, _allFiles[b].Path, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allFiles.Count]; int index = 0; foreach (var file in _allFiles) { _allPhotos[index++] = new Photo(file, _imageFactory); } // 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 static CompositionImageFactory CreateCompositionImageFactory(Compositor compositor) { return(CompositionImageFactory.CreateCompositionImageFactory(compositor)); }
private void CreateImageFactory(UIElement element) { visual = GetVisual(element); compositor = GetCompositor(visual); imageFactory = CreateCompositionImageFactory(compositor); }
public async Task Create(CompositionImageFactory imageFactory) { _random = new Random(); _imageFactory = imageFactory; _allFiles = new List <StorageFile>(); // Search pictures to build File 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 < _allFiles.Count - 1; a++) { for (int b = a + 1; b < _allFiles.Count; b++) { if (String.Equals( _allFiles[a].Path, _allFiles[b].Path, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allFiles.Count]; int index = 0; foreach (var file in _allFiles) { _allPhotos[index++] = new Photo(file, _imageFactory); } // 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> /// 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(); }
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); }
private void CreateImageFactory(UIElement element) { if (visual == null) visual = GetVisual(element); compositor = GetCompositor(visual); //visual.Clip = compositor.CreateInsetClip(0, 0, 0, 0); if (imageFactory == null) imageFactory = CreateCompositionImageFactory(compositor); //<=== this causes a hige growth in memory footprint }