예제 #1
0
 public static void Erasing(this CanvasDrawingSession session, ICanvasImage mask, float o = 1)
 {
     session.DrawImage(
         mask, mask.GetBounds(session.Device), mask.GetBounds(session.Device),
         o, CanvasImageInterpolation.Linear, CanvasComposite.DestinationOut
         );
 }
예제 #2
0
        /// <summary>
        /// Turn into icon render image.
        /// </summary>
        /// <param name="canvasImage"> The canvas image. </param>
        /// <param name="resourceCreator"> The resource creator. </param>
        /// <param name="actualHeight"> The actual height. </param>
        /// <returns> The product image. </returns>
        public static ICanvasImage ToIconRenderImage(this ICanvasImage canvasImage, ICanvasResourceCreator resourceCreator, float actualHeight)
        {
            Rect bound = canvasImage.GetBounds(resourceCreator);

            return(new Transform2DEffect
            {
                TransformMatrix = bound.ToIconRenderMatrix(LayerManager.ControlsHeight),
                Source = canvasImage,
            });
        }
        private void ImageCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            if (_canvasImage == null)
            {
                ds.Clear(Colors.White);
                return;
            }

            var imageBounds = _canvasImage.GetBounds(sender);
            var min         = Math.Min(imageBounds.Height, imageBounds.Width);

            imageBounds.X      = (imageBounds.Width - min) / 2;
            imageBounds.Y      = (imageBounds.Height - min) / 2;
            imageBounds.Height = min;
            imageBounds.Width  = min;

            ds.Clear(Colors.White);
            ds.DrawImageWithEffect(_canvasImage, new Rect(0, 0, 950, 950), imageBounds, _selectedEffectType);
        }
예제 #4
0
        private void DrawBitmap1(CanvasDrawingSession ds, Size size)
        {
            Rect rect = new Rect(size.Width / 2,
                                 size.Height / 2,
                                 size.Width / 2,
                                 size.Height / 2);


            if (bitmap1 != null)
            {
                var sourceRect = new Rect(0, 0, bitmap1.GetBounds(CanvasDevice.GetSharedDevice()).Width, bitmap1.GetBounds(CanvasDevice.GetSharedDevice()).Height);

                ds.DrawImage(bitmap1, rect, sourceRect);
            }
        }
예제 #5
0
        //@Static
        /// <summary>
        /// Gets a specific rended-layer.
        /// </summary>
        /// <param name="transform"> The transform. </param>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="image"> The source image. </param>
        /// <param name="matrix"> The matrix. </param>
        /// <returns> The rendered image. </returns>
        public static ICanvasImage Render(Transform transform, ICanvasResourceCreator resourceCreator, ICanvasImage image, Matrix3x2 matrix)
        {
            if (transform.IsCrop == false)
            {
                return(image);
            }


            CanvasGeometry    canvasGeometry    = transform.CropTransformer.ToRectangle(resourceCreator, matrix);
            CanvasCommandList canvasCommandList = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession drawingSession = canvasCommandList.CreateDrawingSession())
            {
                drawingSession.FillGeometry(canvasGeometry, Colors.Gray);

                Rect cropRect = image.GetBounds(resourceCreator);
                drawingSession.DrawImage(image, (float)cropRect.X, (float)cropRect.Y, cropRect, 1.0f, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.SourceIn);
            }
            return(canvasCommandList);
        }
예제 #6
0
        async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
        {
            // Draw the icon image into a command list.
            var commandList = new CanvasCommandList(device);

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

            ICanvasImage iconImage = commandList;

            // 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;

                var 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);

                if (iconInfo.Monochrome)
                {
                    // Optionally convert to monochrome.
                    iconImage = new DiscreteTransferEffect
                    {
                        Source = new Transform2DEffect
                        {
                            Source = new LuminanceToAlphaEffect {
                                Source = iconImage
                            },
                            TransformMatrix = transform
                        },

                        RedTable   = new float[] { 1 },
                        GreenTable = new float[] { 1 },
                        BlueTable  = new float[] { 1 },
                        AlphaTable = new float[] { 0, 1 }
                    };
                }
                else
                {
                    ds.Transform = transform;

                    // Optional shadow effect.
                    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);
            }
        }
        public async Task ShowAsync(PhotoData photo)
        {
            if (photo == null || photo.Uri == null)
            {
                return;
            }

            Root.Opacity    = 0;
            Root.Visibility = Visibility.Visible;

            LoadingScreen.Opacity          = 1;
            LoadingScreen.IsHitTestVisible = true;
            ProgressRing.IsActive          = true;

            await Root.Scale(1.2f, 1.2f, (float)ActualWidth / 2, (float)ActualHeight / 2, 0).Then()
            .Fade(1).Scale(1, 1, (float)ActualWidth / 2, (float)ActualHeight / 2).StartAsync();

            _photo = photo;
            var uri = new Uri(photo.Uri);

            if (uri.IsFile)
            {
                _file = await StorageFile.GetFileFromPathAsync(photo.Uri);
            }
            else
            {
                _file = await StorageFile.CreateStreamedFileFromUriAsync("photo.jpg", uri, null);
            }

            if (_file == null)
            {
                Hide();
                return;
            }

            var stream = await _file.OpenReadAsync();

            _canvasImage = await CanvasBitmap.LoadAsync(ImageCanvas, stream);

            var imgBounds = _canvasImage.GetBounds(ImageCanvas);

            //var size = Math.Min(imgBounds.Height, imgBounds.Width);

            ImageCanvas.Height = 1200;
            ImageCanvas.Width  = 950;

            _selectedEffectType = EffectType.none;
            ImageCanvas.Invalidate();

            if (_photo.InkUri != null)
            {
                Inker.LoadInkFromFile(_photo.InkUri);
            }

            if (App.IsXbox())
            {
                DetailsButton.Focus(FocusState.Keyboard);
            }

            SetCanvasSize();

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            ((App)(App.Current)).BackRequested += PhotoPreviewView_BackRequested;

            SizeChanged           += PhotoPreviewView_SizeChanged;
            ImageRoot.SizeChanged += ImageRoot_SizeChanged;
            SetCanvasSize();

            LoadingScreen.Fade(0, 300).Start();
            ProgressRing.IsActive          = false;
            LoadingScreen.IsHitTestVisible = false;

            FinishedShowing?.Invoke(this, null);

            IsVisible = true;

            AnalyzeFaces();
        }
예제 #8
0
        public static void DrawImage(this CanvasDrawingSession session, ICanvasImage image, float opacity)
        {
            var rect = image.GetBounds(session);

            session.DrawImage(image, rect, rect, opacity);
        }
예제 #9
0
    public static void DrawImage(this CanvasDrawingSession t, ICanvasImage ii, CanvasComposite c, float o = 1)
    {
        var bb = ii.GetBounds(t.Device);

        t.DrawImage(ii, bb, bb, o, CanvasImageInterpolation.Linear, c);
    }
예제 #10
0
 public static void DrawImage(this CanvasDrawingSession session, ICanvasImage image, float opacity)
 {
     var rect = image.GetBounds(session);
     session.DrawImage(image, rect, rect, opacity);
 }