Another busy week and I feel thrilled to announce the release of CompositionProToolkit v0.4.3. It mainly contains feature additions to CompositionImageFrame and some minor refactoring (no breaking changes!). Let’s delve into the details.

CompositionGeneratorFactory

CompositionGeneratorFactory APIs have been simplified further. Now there are two ways to obtain the CompositionGenerator – by providing a Compositor or by providing a CompositionGraphicDevice.

public static ICompositionGenerator GetCompositionGenerator(Compositor compositor, bool useSharedCanvasDevice = true, bool useSoftwareRenderer = false); public static ICompositionGenerator GetCompositionGenerator( CompositionGraphicsDevice graphicsDevice);

The first API also has couple of optional parameters

useSharedCanvasDevice – indicates whether the CompositionGenerator should use a shared CanvasDevice or creates a new one.

– indicates whether the should use a shared or creates a new one. useSoftwareRenderer – this parameter is provided as a argument when creating a new CanvasDevice (i.e. when usedSharedCanvasDevice is false).

ICompositionMask

Two new APIs have been added in ICompositionMask class which allow the redraw of the mask with a new Color or ICanvasBrush.

void Redraw(ICanvasBrush brush); void Redraw(Color color);

CompositionImageFrame

CompositionImageFrame has received most attention in this release. Two of the most requested features – Placeholder and Image Caching, have now been incorporated into CompositionImageFrame. Also now whenever the AlignX or AlignY changes, the image animates to its new location.

When the image is being (cached and) loaded, the placeholder shows a progress bar which indicates the load progress.

The following new properties have been added to CompositionImageFrame to configure the Placeholder and the Image Cache features.

Property Type Description Default value ShowPlaceHolder Boolean Indicates whether the placeholder needs to be displayed during image load or when no image is loaded in the CompositionImageFrame. False PlaceholderBackground Color Indicates the background color of the Placeholder. Colors.Black PlaceholderColor Color Indicates the color with which the rendered placeholder geometry should be filled RGB(192, 192, 192) UseImageCache Boolean Indicates whether the images should be cached before rendering them. True

Using CompositionImageFrame with FilePicker

If you have a CompostionImageFrame control in you application and your want to use the FilePicker to select an image file to be displayed on the CompostionImageFrame, then you must do the following

var picker = new Windows.Storage.Pickers.FileOpenPicker { ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail, SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary }; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); ImageFrame.Source = await ImageCache.GetCachedUriAsync(file);

Since the CompositionImageFrame‘s Source property expects a Uri, while the FilePicker provides a StorageFile. So in order to obtain a Uri from the StorageFile, you must first cache it using the ImageCache.GetCachedUriAsync() method.

The latest source code is available in GitHub and NuGet package is available here.