Cómo obtener la dimensión de imagen del nombre del archivo


Tengo un archivo llamado FPN = "c:\ggs\ggs Acceso\imágenes\miembros\1.jpg "

Estoy tratando de obtener la dimensión de la imagen 1.jpg, y me gustaría comprobar si la dimensión de la imagen es válida o no antes de cargar, y si el ancho o el alto de la imagen es menor o igual a cero, aparece un mensaje como "imagen no en formato correcto"

¿Alguien puede ayudarme, por favor?

Author: Il Vic, 2011-06-23

2 answers

System.Drawing.Image img = System.Drawing.Image.FromFile(@"c:\ggs\ggs Access\images\members\1.jpg");
MessageBox.Show("Width: " + img.Width + ", Height: " + img.Height);
 103
Author: John T,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-23 15:10:19

La clase Wpf System.Windows.Media.Imaging.BitmapDecoder no lee el archivo completo, solo los metadatos.

using(var imageStream = File.OpenRead("file"))
{
        var decoder = BitmapDecoder.Create(imageStream, BitmapCreateOptions.IgnoreColorProfile,
            BitmapCacheOption.Default);
        var height = decoder.Frames[0].PixelHeight;
        var width = decoder.Frames[0].PixelWidth;
}
 27
Author: Atomosk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-27 04:15:56