Exemplo n.º 1
0
 private void Resize(string fullPath, ResizeRule rule)
 {
     if (rule.Width.HasValue && !rule.Height.HasValue)
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImageW(binary, rule.Width.Value, outputPath);
     }
     else if (rule.Height.HasValue && !rule.Width.HasValue)
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImageH(binary, rule.Height.Value, outputPath);
     }
     else
     {
         var binary     = BinaryHelper.FromImageToString(fullPath);
         var outputPath = Path.Combine(rule.OutputPath, Path.GetFileName(fullPath));
         ImageHelper.ResizeImage(binary, rule.Width.Value, rule.Height.Value, outputPath);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Find the most appropriate resoluton depending on the specified resize rule
        /// </summary>
        /// <param name="rule">Resize rule</param>
        /// <param name="width">Width</param>
        /// <param name="height">Height</param>
        /// <returns>Returns the display mode if found, otherwise null</returns>
        private DisplayMode FindFullScreenResolution(ResizeRule rule, int width, int height)
        {
            ReadOnlyCollection<DisplayMode> availableModes = GetAvailableModes();
            if ((availableModes == null) || (availableModes.Count == 0)) return null;

            DisplayMode mode = null;
            switch (rule)
            {
                case ResizeRule.Lowest: mode = availableModes[0];
                    break;
                case ResizeRule.Highest: mode = availableModes[availableModes.Count - 1];
                    break;
                case ResizeRule.Nearest: mode = FindNearestResolution(width, height, availableModes);
                    break;
            }

            return mode;
        }