Beispiel #1
0
        /// <summary>
        /// Reads the <see cref="System.Drawing.Size"/> of an image from the file.
        /// </summary>
        /// <param name="imagePath"> Path to the image. </param>
        /// <returns>
        /// The <see cref="System.Drawing.Size"/> of the image; otherwise <see cref="Size.Empty"/>.
        /// </returns>
        public static Size GetImageDimensionsFromFile(string imagePath)
        {
            if (string.IsNullOrEmpty(imagePath) || !File.Exists(imagePath))
            {
                return(Size.Empty);
            }

            Size s = ImageBinaryReader.GetDimensions(imagePath);

            if (s != Size.Empty)
            {
                return(s);
            }

            try
            {
                using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (Image image = Image.FromStream(fileStream, false, false))
                    {
                        return(new Size(image.Width, image.Height));
                    }
            }
            catch
            {
                return(Size.Empty);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Reads the <see cref="ImgFormat"/> of an image using the identifier bytes.
 /// </summary>
 /// <param name="path">The path to the file.</param>
 /// <returns>
 /// The <see cref="ImgFormat"/> of the image.
 /// </returns>
 public static ImgFormat GetImageFormat(string path)
 {
     return(ImageBinaryReader.GetImageFormat(path));
 }