//Retrieves the bitmap with the matching resource name static public CanvasBitmap getImageByName(string resourceName) { //The result CanvasBitmap result = null; //If initialized if (initialized) { //For each loaded image for (int index = 0; index < loadedImages.Count; index++) { //Get the current image ImageManagerResource currentImageResource = loadedImages[index]; //If the resource name matches if (resourceName.Equals(currentImageResource.name)) { //Set the result result = currentImageResource.image; //End the loop break; } } } //Return the result return(result); }
//Loads an image at the given path static public void LoadImage(string resourceName, string path) { //If initialized if (initialized) { //The loaded image CanvasBitmap image = null; //Create and start a timer Stopwatch timer = new Stopwatch(); timer.Start(); //Begin loading image IAsyncOperation <CanvasBitmap> loadingOperation = CanvasBitmap.LoadAsync(canvasControl, path, 50); //Until loading is completed or times out while (loadingOperation.Status != AsyncStatus.Completed && timer.ElapsedMilliseconds < LOADING_TIMEOUT) { //Wait } //Stop the timer timer.Stop(); //Retrieve the image image = loadingOperation.GetResults(); //Create a new image resource ImageManagerResource resource = new ImageManagerResource(); resource.name = resourceName; resource.path = path; resource.image = image; //Add the new resource to the index loadedImages.Add(resource); } }