static void DrawSecondsText(CanvasDrawingSession ds, Vector2 pos, int seconds)
        {
            // The text is drawn via a command list so we can use DrawImage to specify a difference CanvasComposite mode.
            using (var cl = new CanvasCommandList(ds))
            {
                using (var clds = cl.CreateDrawingSession())
                {
                    clds.DrawText(seconds.ToString(), Vector2.Zero, Colors.White, textFormat);
                }

                Rect textBounds = cl.GetBounds(ds);
                var offset = new Vector2((float)textBounds.Left, (float)textBounds.Top);

                ds.DrawImage(cl, pos + offset, cl.GetBounds(ds), 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.MaskInvert);
            }
        }
示例#2
0
        async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
        {
            // Draw the icon image into a command list.
            var iconImage = new CanvasCommandList(device);

            using (var ds = iconImage.CreateDrawingSession())
            {
                appInfo.DrawIconImage(ds, iconInfo);
            }

            // Rasterize into a rendertarget.
            var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                // Initialize with the appropriate background color.
                ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor);

                // Work out where to position the icon image.
                var imageBounds = iconImage.GetBounds(ds);

                imageBounds.Height *= 1 + iconInfo.BottomPadding;

                float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f);

                float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons;

                ds.Transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) *
                               Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) *
                               Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2);

                // Optional shadow effet.
                if (appInfo.AddShadow)
                {
                    var shadow = new ShadowEffect
                    {
                        Source     = iconImage,
                        BlurAmount = 12,
                    };

                    ds.DrawImage(shadow);
                }

                // draw the main icon image.
                ds.DrawImage(iconImage);
            }

            // Save to a file.
            using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting))
            {
                await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png);
            }
        }
示例#3
0
        public static CanvasBitmap GetCanvasBitmap(this CanvasCommandList canvasCommandList)
        {
            var chartRect = canvasCommandList.GetBounds(canvasCommandList.Device);
            var offScreen = new CanvasRenderTarget(canvasCommandList.Device, (float)chartRect.Width,
                                                   (float)chartRect.Height, 96);
            var chartOffset = new Point(-chartRect.X, -chartRect.Y).ToVector2();

            using (var session = offScreen.CreateDrawingSession())
            {
                session.Transform = Matrix3x2.CreateTranslation(chartOffset);
                session.DrawImage(canvasCommandList);
            }
            return(offScreen);
        }
        static void DrawSecondsText(CanvasDrawingSession ds, Vector2 pos, int seconds)
        {
            // The text is drawn via a command list so we can use DrawImage to specify a difference CanvasComposite mode.
            using (var cl = new CanvasCommandList(ds))
            {
                using (var clds = cl.CreateDrawingSession())
                {
                    clds.DrawText(seconds.ToString(), Vector2.Zero, Colors.White, textFormat);
                }

                Rect textBounds = cl.GetBounds(ds);
                var offset = new Vector2((float)textBounds.Left, (float)textBounds.Top);

                ds.DrawImage(cl, pos + offset, cl.GetBounds(ds), 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.MaskInvert);
            }
        }
示例#5
0
        async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
        {
            // Draw the icon image into a command list.
            var iconImage = new CanvasCommandList(device);

            using (var ds = iconImage.CreateDrawingSession())
            {
                appInfo.DrawIconImage(ds, iconInfo);
            }

            // Rasterize into a rendertarget.
            var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                // Initialize with the appropriate background color.
                ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor);

                // Work out where to position the icon image.
                var imageBounds = iconImage.GetBounds(ds);

                imageBounds.Height *= 1 + iconInfo.BottomPadding;

                float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f);

                float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons;

                ds.Transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) *
                               Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) *
                               Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2);

                // Optional shadow effet.
                if (appInfo.AddShadow)
                {
                    var shadow = new ShadowEffect
                    {
                        Source = iconImage,
                        BlurAmount = 12,
                    };

                    ds.DrawImage(shadow);
                }

                // draw the main icon image.
                ds.DrawImage(iconImage);
            }

            // Save to a file.
            using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting))
            {
                await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png);
            }
        }