private void LoadAndDisplayFile(PostImageLoad afterLoadFn) { const string imageFilter = "Image Files (*.bmp, *.png, *.jpg)|*.bmp;*.png;*.jpg|GT2 Files (*.gtmp, *.gm, *.gz)|*.gtmp;*.gm;*.gz|All Files (*.*)|*.*"; string fileName = GetOpenFileName(this, "Open an image", imageFilter, null); if (String.IsNullOrEmpty(fileName)) { return; } LoadAndDisplaySelectedFile(fileName, afterLoadFn); }
private void LoadAndDisplaySelectedFile(string fileName, PostImageLoad afterLoadFn) { DebugLogger.Log("Main", "Loading {0} with afterloader {1}...", fileName, afterLoadFn.Method.Name); try { Images.ImageLoadResult imageload = Images.LoadFile(fileName); DebugLogger.Log("Main", "...Image was a {0}", imageload.type.ToString()); Bitmap image = imageload.image; if ((image.Width != CANVAS_WIDTH) || (image.Height != CANVAS_HEIGHT)) { DisplayMsgBox(MessageBoxButtons.OK, MessageBoxIcon.Warning, "'{0}' was loaded, but it's the wrong size {1}. Should be {2}x{3}", Path.GetFileName(fileName), image.Size, CANVAS_WIDTH, CANVAS_HEIGHT); image.Dispose(); return; } afterLoadFn(fileName, imageload); } catch (Exception e) { DisplayMsgBox(MessageBoxButtons.OK, MessageBoxIcon.Error, "Failed to load {0} because of error {1}", fileName, e.Message); } }