I have a map. It can be zoomed-in and out. At first, I used one large image. Scrolling the mouse wheel defined the desired zoom level. Every scrolling created a new instance of the image in the desired dimensions. This approach was horribly slow.
So I gave up the possibility of zooming into any level, and created a list of predefined available zoom levels, ranging from 35% to 100% with 5% intervals, and then up to 300% with 50% intervals. For each zoom level, I have created a copy of the original image with the appropriate dimensions. The image name corresponds to its dimensions, so a 35% image is called "35.jpg". I added the images to the project's resources in a dedicated folder. Visual Studio automatically inserts an underline before the object's name because it starts with a number, so the object that represents the file is called "_35". So now, after the desired zoom level has been determined by the mouse wheel, the corresponding image is loaded from the resources. Performance has improved significantly.
Some of the application's components need a list of all available zoom levels. For example, for a ComboBox
that allows the user to select a specific zoom level, rather than reach it through the mouse wheel. Therefore, when loading the form, a List<float>
is initialized with all available zoom dimensions, so a 35% zoom is saved as 0.35 (a floating point representation is required by most components that uses the list) . The initialization is done by importing the names of the objects from the resources.
Here is the method that extracts file names and parse them into float
. I feel it is not well written but I cannot point to a specific problem. I would love to hear your opinion. Thanks!
private static void InitializeZoomFactorsList()
{
ResourceSet images = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
List<string> names = images.Cast<DictionaryEntry>().Select(item => item.Key.ToString()).ToList();
List<float> factors = names.ConvertAll<float>(delegate(string i) { return float.Parse(i.Substring(1, i.Length - 1)) / 100; });
factors.Sort(); // because the list was strings, 300 came before 90, so after the parsing, I sort it by the value.
zoomFactorsList = factors;
}
}
. A copy/paste error or is this just pseudocode? \$\endgroup\$