Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: AddProfile causes NullReferenceException

$
0
0
I think I was aware of how the constructor worked, I only used the constructer to generate the Exif from the path to my image file which should be allowed according to the specification. I think i misunderstood the GetExifProfile method on a MagickImage, I thought it would be able to pull out the Exif data from the image i loaded into the MagickImage that's at least the way i understood the documentation: Read exif data this did not work however, simply returned null even though the constructor new ExifProfile(path) references the same image file.
The error with Exif not always being loaded I had trouble recreating, I might have tested that with a .crw which didn't contain Exif data and hence hit the exception when adding the profile, so thus far I don't think sharing the image makes any sense :)

I did however stumble upon another interesting thing where I can share some images with you:
Converting .cr2 files to .jpg files mirrors the image(flips/flops it) at least when the Exif orientation is 6 or 8(this didn't happen when orientation was 1).
You should notice it with the following files:
https://www.rawsamples.ch/raws/canon/1dsm2/RAW_CANON_1DSM2.CR2 (Orientation 8)
https://www.rawsamples.ch/raws/canon/RAW_CANON_EOS70D.CR2 (Orientation 6)

So far I changed my code so that it flips/flops the image if it is 6 or 8, I do not know whether or not it happens with other raw formats but with all Canon's it is the case.
I parsed the images through the following code to notice it:
        public static void ConvertRawImage(string path)
        {
            ExifProfile exif = new ExifProfile(path);

            MagickReadSettings settings = new MagickReadSettings();
            settings.Format = MagickFormat.Cr2;
            try
            {
                using (MagickImage image = new MagickImage(path, settings))
                {
                    if (exif.Values.Count() > 0)
                    {
                        image.AddProfile(exif);
                    }
                    image.Quality = 95;

                    image.Write(GetFullPathWithoutExtension(path) + ".jpg");
                }
            }
            catch (MagickException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
"Also checking 'if (exif != null)' makes no sense to me because you are using a constructor." I think, I went into a rampage trying to find the null exception, this of course isn't needed as you pointed out, I have cleaned up my code :)

Thanks for the answers so far! :)

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>