Esempio n. 1
0
        private void UpdateImageSourceForDpi(Image image)
        {
            string newImageUrl = ImageDpiHelper.GetDesiredImageUrlForDpi(image);

            ImageDpiHelper.UpdateImageSource(image, newImageUrl);
            textLabel.Text = newImageUrl + " for DPI of " + (/*VisualTreeHelper.GetDpi(image).PixelsPerDip **/ 100);
        }
Esempio n. 2
0
        private void ScaleRightImage(DpiScaleInfo newDpi)
        {
            // update bestScale
            bestScale = ImageDpiHelper.GetBestScale(newDpi.PixelsPerDip);

            string imageUrl = ImageDpiHelper.GetDesiredImageUrlForDpi(this);

            UpdateImageSource(this, imageUrl);
        }
Esempio n. 3
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)
        {
            DpiScale 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);
        }