private void GuessImageDimensions(string imagePath, out int imageWidth, out int imageHeight) { using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(imagePath))) { using (Image picture = Image.FromStream(ms)) { imageHeight = picture.Height; imageWidth = picture.Width; } } }