none
How can I read an Image File's Information?

    Question

  • Hello all,

         I am currently making a program to read the Extended Properties information on an image file. What I mean by this is that I want to read information such as Width, Height, Vertical and Horizontal Resolution, Bit Depth, Frame Count, and Color Representation, among others. Is there any way to read all of this information?


         While I'm on the subject, I wanted to ask about the summary page on a files properties. When you right-click a file and choose properties, then go to the tab called Summary, you see a list of values, which are Title, Subject, Author, Category, Keywords, and Comments. But I'm not talking about those. The is a button, further below, that reads "Advanced >>". When pressed, you are brought to a screen that has various PropertyValue listings. As you may or may not know, each of these listings is unique to a each file type. A Word document will give you Character Count, while an AVI will give you Video Compression. What I want to know is, is there some way to read all of these properties, no matter what type of file? I dont mean getting into specifics: asking for a word documents word count, character count, etc. I mean just a generic way of reading into a file's Extended Properties.
    • Edited by TheBlueCard Thursday, June 25, 2009 2:19 AM
    Thursday, June 25, 2009 2:03 AM

Answers

  • Is fileProps null?

    I modified the code that calls the GetFileProps method to display the returned properties:

        private void button1_Click(object sender, EventArgs e)
        {
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.ShowDialog();
          Dictionary<int, KeyValuePair<string, string>> fileProps = GetFileProps(ofd.FileName);
          foreach (KeyValuePair<int,KeyValuePair<string, string>> kv in fileProps)
          {
            Console.WriteLine(kv.ToString());
          }
       }
    Here is an example of the output for the Autumn Leaves.jpg sample picture:

    [0, [Name, Autumn Leaves]]
    [1, [Size, 269 KB]]
    [2, [Type, JPEG Image]]
    [3, [Date modified, 2/22/2009 4:51 PM]]
    [4, [Date created, 11/2/2006 11:06 AM]]
    [5, [Date accessed, 11/2/2006 11:05 AM]]
    [6, [Attributes, A]]
    [9, [Perceived type, Image]]
    [10, [Owner, I7\John]]
    [11, [Kinds, Picture]]
    [12, [Date taken, ?11/?4/?2005 ??9:12 PM]]
    [18, [Tags, Sample; Landscape]]
    [19, [Rating, 3 Stars]]
    [20, [Authors, Peter Miller]]
    [21, [Title, Maple leaves in Autumn.]]
    [31, [Dimensions, ?1024 x 768?]]
    [52, [Computer, I7 (this computer)]]
    This is the output for Notepad.exe:

    [0, [Name, notepad.exe]]
    [1, [Size, 165 KB]]
    [2, [Type, Application]]
    [3, [Date modified, 1/20/2008 10:47 PM]]
    [4, [Date created, 1/20/2008 10:47 PM]]
    [5, [Date accessed, 1/20/2008 10:47 PM]]
    [6, [Attributes, A]]
    [9, [Perceived type, Application]]
    [10, [Owner, I7\John]]
    [11, [Kinds, Program]]
    [19, [Rating, Unrated]]
    [25, [Copyright, © Microsoft Corporation. All rights reserved.]]
    [33, [Company, Microsoft Corporation]]
    [34, [File description, Notepad]]
    [52, [Computer, I7 (this computer)]]
    
    • Marked as answer by TheBlueCard Friday, June 26, 2009 1:03 PM
    Friday, June 26, 2009 6:50 AM

All replies

  • Thursday, June 25, 2009 3:20 AM
  • I've used DSOFile in the past. In truth, it is only very useful when reading from Office Document files, as the values that you can read with DSOFile all pertain to said. What I mean is, it will only give you values such as Template, Pages, Word Count, Character Count, etc. which pertain to Microsoft Word (along with other Office files).
    Thursday, June 25, 2009 3:58 AM
  • try Using Bitmap or Image class of .NET framework
    Thursday, June 25, 2009 8:04 AM
  • You can get some help here - Microsoft MSDN Library

    And waht you want exactly the go here : - this is what exactly you are looking for. You want Width, Height, Vertical and Horizontal Resolution, Bit Depth, Frame Count, and Color Representation. Then YOU WILL GET IT IN THIS LINK.

    Cheers!




    Midnight Programmer http://www.midnightprogrammer.net
    Thursday, June 25, 2009 8:29 AM
  • using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.IO;
    using Shell32;  //Reference Microsoft Shell Controls And Automation 
    
    namespace WindowsApplication6
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.ShowDialog();
          Dictionary<int, KeyValuePair<string, string>> fileProps = GetFileProps(ofd.FileName);
        }
        Dictionary<int, KeyValuePair<string, string>> GetFileProps(string filename)
        {
          Shell shl = new ShellClass();
          Folder fldr = shl.NameSpace(Path.GetDirectoryName(filename));
          FolderItem itm = fldr.ParseName(Path.GetFileName(filename));
          Dictionary<int, KeyValuePair<string, string>> fileProps = new Dictionary<int, KeyValuePair<string, string>>();
          for (int i = 0; i < 100; i++)
          {
            string propValue = fldr.GetDetailsOf(itm, i);
            if (propValue != "")
            {
              fileProps.Add(i, new KeyValuePair<string, string>(fldr.GetDetailsOf(null, i), propValue));
            }
          }
          return fileProps;
        }
      }
    }
    Thursday, June 25, 2009 10:15 AM
  • Thank you very much Prashant, thats exactly what I needed for the images. However, do you have any idea on my other question? About how one would go about arbitrarily reading a files extended properties page? Also, do you have any idea on how to read the same type of information, only for a video file instead of an image file? Information such as Width, Height, Duration, Bit Rate, Data Rate, Frame Rate, Audio Sample Size, Video Sample Size, Audio Format, and Video Compression? Thanks again.
    Friday, June 26, 2009 1:50 AM
  • The code I posted reads the extended properties for any file.

    Friday, June 26, 2009 5:22 AM
  • Really? Sorry, but I couldn't get it to work.

    When I execute the code, nothing happens. No values are returned.
    Friday, June 26, 2009 6:05 AM
  • Is fileProps null?

    I modified the code that calls the GetFileProps method to display the returned properties:

        private void button1_Click(object sender, EventArgs e)
        {
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.ShowDialog();
          Dictionary<int, KeyValuePair<string, string>> fileProps = GetFileProps(ofd.FileName);
          foreach (KeyValuePair<int,KeyValuePair<string, string>> kv in fileProps)
          {
            Console.WriteLine(kv.ToString());
          }
       }
    Here is an example of the output for the Autumn Leaves.jpg sample picture:

    [0, [Name, Autumn Leaves]]
    [1, [Size, 269 KB]]
    [2, [Type, JPEG Image]]
    [3, [Date modified, 2/22/2009 4:51 PM]]
    [4, [Date created, 11/2/2006 11:06 AM]]
    [5, [Date accessed, 11/2/2006 11:05 AM]]
    [6, [Attributes, A]]
    [9, [Perceived type, Image]]
    [10, [Owner, I7\John]]
    [11, [Kinds, Picture]]
    [12, [Date taken, ?11/?4/?2005 ??9:12 PM]]
    [18, [Tags, Sample; Landscape]]
    [19, [Rating, 3 Stars]]
    [20, [Authors, Peter Miller]]
    [21, [Title, Maple leaves in Autumn.]]
    [31, [Dimensions, ?1024 x 768?]]
    [52, [Computer, I7 (this computer)]]
    This is the output for Notepad.exe:

    [0, [Name, notepad.exe]]
    [1, [Size, 165 KB]]
    [2, [Type, Application]]
    [3, [Date modified, 1/20/2008 10:47 PM]]
    [4, [Date created, 1/20/2008 10:47 PM]]
    [5, [Date accessed, 1/20/2008 10:47 PM]]
    [6, [Attributes, A]]
    [9, [Perceived type, Application]]
    [10, [Owner, I7\John]]
    [11, [Kinds, Program]]
    [19, [Rating, Unrated]]
    [25, [Copyright, © Microsoft Corporation. All rights reserved.]]
    [33, [Company, Microsoft Corporation]]
    [34, [File description, Notepad]]
    [52, [Computer, I7 (this computer)]]
    
    • Marked as answer by TheBlueCard Friday, June 26, 2009 1:03 PM
    Friday, June 26, 2009 6:50 AM
  • For reading metadata information of Video files in c# check the below links:

    CodeProject

    MSDN


    Best Regards

    Prashant
    Midnight Programmer http://www.midnightprogrammer.net
    Friday, June 26, 2009 8:12 AM
  • @JohnWein

    Thanks for the updated code, it works just fine now.


    @Prashant

    Thank you for everything, you've been a great help.
    Friday, June 26, 2009 1:02 PM
  • I tried using the code above with Visual Studio 2005 but was not able to find the correct assemply to reference for the mehod "GetFileProps" to be recognized. I looked through various postings and was not able to find additional information. Any information would be appeciated.
    mm
    Sunday, December 20, 2009 6:07 AM
  • The .NET references should be included when you start a Windows Forms Application.  Every version of Windows must have shell32.dll.  What reference can't you find?
    Sunday, December 20, 2009 7:05 AM
  • hi..

    I want to know how to get the length and width of a pixel in an image using c# .. does anyone know how to do this?


    Saturday, June 04, 2011 2:03 PM
  • hi..

    I want to know how to get the length and width of a pixel in an image using c# .. does anyone know how to do this?



    The reciprocal of the resolution:  inches per dot.
    Saturday, June 04, 2011 2:06 PM
  • And what do to to get video resolution? I tried the code above, and it gives me the name/size etc. but not the resolution.
    Monday, September 19, 2011 5:38 PM
  • And what do to to get video resolution? I tried the code above, and it gives me the name/size etc. but not the resolution.

    You should get the same info from my code that you get from right clicking the file in Explorer and selecting the Details tab in Properties.
    Monday, September 19, 2011 8:11 PM