示例#1
0
        private IntPtr GetWin32InfoFromUIElement(System.Windows.UIElement uiElement, out System.Drawing.Rectangle rect)
        {
            // Convert UIElement to Rectangle
            System.Windows.Media.Matrix       matrix;
            System.Windows.PresentationSource presentationSource = System.Windows.PresentationSource.FromVisual(uiElement);
            if (presentationSource == null)
            {
                throw new InvalidOperationException("The specified UiElement is not connected to a rendering Visual Tree.");
            }
            try
            {
                System.Windows.Media.GeneralTransform generalTransform = uiElement.TransformToAncestor(presentationSource.RootVisual);
                System.Windows.Media.Transform        transform        = generalTransform as System.Windows.Media.Transform;
                if (transform == null)
                {
                    throw new ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change");
                }
                matrix = transform.Value;
            }
            catch (InvalidOperationException)
            {
                throw new InvalidOperationException("The specified UiElement is not connected to a rendering Visual Tree.");
            }
            System.Windows.Rect rect1 = new System.Windows.Rect(new System.Windows.Point(), uiElement.RenderSize);
            rect1.Transform(matrix);
            System.Windows.Point point1 = rect1.TopLeft;
            point1 = presentationSource.CompositionTarget.TransformToDevice.Transform(point1);
            Point  point2 = new Point((int)point1.X, (int)point1.Y);
            IntPtr hwnd   = ((System.Windows.Interop.HwndSource)presentationSource).Handle; // PresentaionSource.RootVisual ?

            User32.ClientToScreen(hwnd, ref point2);
            rect = new System.Drawing.Rectangle(point2, new System.Drawing.Size(
                                                    Convert.ToInt32(Microsoft.Test.Display.Monitor.ConvertLogicalToScreen(Microsoft.Test.Display.Dimension.Width, uiElement.RenderSize.Width)),
                                                    Convert.ToInt32(Microsoft.Test.Display.Monitor.ConvertLogicalToScreen(Microsoft.Test.Display.Dimension.Height, uiElement.RenderSize.Height))));

            return(hwnd);
        }
示例#2
0
        public void generateThumbnail(MediaProbe mediaProbe, ImageMetadata image,
                                      CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
            // possibly could not seek in video, try to get the first frame in the video
            List <MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                                                                       Constants.MAX_THUMBNAIL_HEIGHT, 0, 1, 0, token, timeoutSeconds, null);

            if (thumbBitmaps.Count > 0)
            {
                BitmapSource thumb = thumbBitmaps[0].Thumb;

                if (image.Orientation.HasValue && image.Orientation.Value != 1)
                {
                    System.Windows.Media.Transform transform = null;

                    switch (image.Orientation.Value)
                    {
                    case 2:
                    {
                        //Mirror horizontal
                        transform = new System.Windows.Media.MatrixTransform(-1, 0, 0, 1, 0, 0);
                        break;
                    }

                    case 3:
                    {
                        //Rotate 180°
                        transform = new System.Windows.Media.RotateTransform(180);
                        break;
                    }

                    case 4:
                    {
                        //Mirror vertical
                        transform = new System.Windows.Media.MatrixTransform(1, 0, 0, -1, 0, 0);
                        break;
                    }

                    case 5:
                    {
                        //Mirror horizontal, rotate 270°
                        transform = new System.Windows.Media.MatrixTransform(0, -1, -1, 0, 0, 0);
                        break;
                    }

                    case 6:
                    {
                        //Rotate 90°
                        transform = new System.Windows.Media.RotateTransform(90);
                        break;
                    }

                    case 7:
                    {
                        //Mirror horizontal, rotate 90°
                        transform = new System.Windows.Media.MatrixTransform(0, 1, 1, 0, 0, 0);
                        break;
                    }

                    case 8:
                    {
                        //Rotate 270°
                        transform = new System.Windows.Media.RotateTransform(270);
                        break;
                    }

                    default:
                    {
                        Logger.Log.Warn("Unknown orientation for image");
                        break;
                    }
                    }

                    if (transform != null)
                    {
                        thumb = new TransformedBitmap(thumb, transform);
                    }
                }

                image.Thumbnail = new Thumbnail(thumb);
            }
            else
            {
                image.Thumbnail = null;
            }
        }
 public TransformedBitmap(BitmapSource source, System.Windows.Media.Transform newTransform)
 {
 }