Пример #1
0
        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();
            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();
            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
Пример #2
0
        private void ScaleRightImage(DpiScaleInfo newDpi)
        {
            // update bestScale
            bestScale = ImageDpiHelper.GetBestScale(newDpi.PixelsPerDip);

            string imageUrl = ImageDpiHelper.GetDesiredImageUrlForDpi(this);
            UpdateImageSource(this, imageUrl);
        }
Пример #3
0
        private void ScaleRightImage(DpiScaleInfo newDpi)
        {
            // update bestScale
            bestScale = ImageDpiHelper.GetBestScale(newDpi.PixelsPerDip);

            string imageUrl = ImageDpiHelper.GetDesiredImageUrlForDpi(this);

            UpdateImageSource(this, imageUrl);
        }
Пример #4
0
        /// <summary>
        /// Given an image, get its current DPI and choose the best source image to scale to that DPI.
        /// </summary>
        /// <param name="image">image element</param>
        /// <returns>image URL for the most appropriate scale, given DPI</returns>
        public static string GetDesiredImageUrlForDpi(Image image)
        {
            DpiScaleInfo imageScaleInfo = VisualTreeHelper.GetDpi(image);
            int          bestScale      = ImageDpiHelper.GetBestScale(imageScaleInfo.PixelsPerDip);

            var    sourceUrl    = image.Source.ToString();
            string imagePattern = Regex.Replace(sourceUrl, ".scale-[0-9]{3}.", ".scale-{0}.");

            string newImagePath = null;

            if (imagePattern != null)
            {
                newImagePath = string.Format(imagePattern, bestScale);
            }

            return(newImagePath);
        }
Пример #5
0
        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();

            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();

            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform      = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
Пример #6
0
 // when DPI changes, ensure we are using the right scaled image, based on the DPI.
 protected override void OnDpiChanged(DpiScaleInfo oldDpi, DpiScaleInfo newDpi)
 {
     ScaleRightImage(newDpi);
 }
Пример #7
0
        // on initial load, ensure we are using the right scaled image, based on the DPI.
        private void DpiAwareImage_Initialized(object sender, EventArgs e)
        {
            DpiScaleInfo newDpi = VisualTreeHelper.GetDpi(sender as Visual);

            ScaleRightImage(newDpi);
        }
Пример #8
0
 // when DPI changes, ensure we are using the right scaled image, based on the DPI.
 protected override void OnDpiChanged(DpiScaleInfo oldDpi, DpiScaleInfo newDpi)
 {
     ScaleRightImage(newDpi);
 }
Пример #9
0
 protected override void OnDpiChanged(DpiScaleInfo oldDpiScaleInfo, DpiScaleInfo newDpiScaleInfo)
 {
     DrawFormattedText(newDpiScaleInfo);
 }
Пример #10
0
 protected override void OnDpiChanged(DpiScaleInfo oldDpiScaleInfo, DpiScaleInfo newDpiScaleInfo)
 {
     DrawFormattedText(newDpiScaleInfo);
 }
Пример #11
0
 protected override void OnDpiChanged(DpiScaleInfo oldDpiScaleInfo, DpiScaleInfo newDpiScaleInfo)
 {
     _pixelsPerDip = newDpiScaleInfo.PixelsPerDip;
     UpdateFormattedText(_pixelsPerDip);
 }
Пример #12
0
 protected override void OnDpiChanged(DpiScaleInfo oldDpiScaleInfo, DpiScaleInfo newDpiScaleInfo)
 {
     _pixelsPerDip = newDpiScaleInfo.PixelsPerDip;
     UpdateFormattedText(_pixelsPerDip);
 }