Search code examples
c#visual-studiometadata-extractor

metadata Extractor library path access denied


I've found this .net library that can extract metadata from images and the example they gave is below however whatever path i put in just gives a path access to the path is denied error. I am running visual studio as an admin so that shouldn't be the issue

static void Main(string[] args)
        {

            var directories = MetadataExtractor.ImageMetadataReader.ReadMetadata("C:\\New folder");

            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                    Console.WriteLine($"[{directory.Name}] {tag.Name} = {tag.Description}");

                if (directory.HasError)
                {
                    foreach (var error in directory.Errors)
                        Console.WriteLine($"ERROR: {error}");
                }
            }

        }

Solution

  • U have to set path to file, not folder. I've try it like this

    C:\\New folder\\maxresdefault.jpg
    

    And it's works. Output:

    [JPEG] Compression Type = Baseline
    [JPEG] Data Precision = 8 bits
    [JPEG] Image Height = 720 pixels
    [JPEG] Image Width = 1280 pixels
    [JPEG] Number of Components = 3
    [JPEG] Component 1 = Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
    [JPEG] Component 2 = Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
    [JPEG] Component 3 = Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
    [JFIF] Version = 1.1
    [JFIF] Resolution Units = inch
    [JFIF] X Resolution = 96 dots
    [JFIF] Y Resolution = 96 dots
    [JFIF] Thumbnail Width Pixels = 0
    [JFIF] Thumbnail Height Pixels = 0
    [Exif IFD0] X Resolution = 96 dots per inch
    [Exif IFD0] Y Resolution = 96 dots per inch
    [Exif IFD0] Resolution Unit = Inch
    [Exif IFD0] Software = paint.net 4.0.19
    [File] File Name = maxresdefault.jpg
    [File] File Size = 121177 bytes
    [File] File Modified Date = Вт май 29 13:45:59 +03:00 2018