Hey guys I have the following code:
The reason for this is that "image.GetExifProfile();" returns null which oddly enough is not the case with "new ExifProfile(path);".
Any help would be appreciated! Do not hesitate to ask me for more info if needed be.
Kind Regards,
Lorentzen1337
public static void ConvertRawImage(string path)
{
ImageProfile exif = new ExifProfile(path);
MagickReadSettings settings = new MagickReadSettings();
settings.Format = MagickFormat.Cr2;
try
{
using (MagickImage image = new MagickImage(path, settings))
{
if (exif != null)
{
image.AddProfile(exif);
}
image.Quality = 95;
image.Write(GetFullPathWithoutExtension(path) + ".jpg");
}
}
catch (MagickException ex)
{
Console.WriteLine(ex.Message);
}
var rawDir = System.IO.Directory.CreateDirectory(Path.GetDirectoryName(path) + @"\RAW");
File.Move(path, rawDir.FullName + @"\" + Path.GetFileName(path));
}
I get the following exception:System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Magick.NET-Q16-AnyCPU
StackTrace:
at ImageMagick.ExifWriter.GetIndexes(ExifParts part, ExifTag[] tags)
at ImageMagick.ExifWriter..ctor(Collection`1 values, ExifParts allowedParts, Boolean bestPrecision)
at ImageMagick.ExifProfile.UpdateData()
at ImageMagick.ImageProfile.ToByteArray()
at ImageMagick.MagickImage.AddProfile(ImageProfile profile, Boolean overwriteExisting)
at ShooterSoftware.Toolbox.ConvertRawImage(string path) i C:\_gitProjects\ShooterSoftware\ShooterSoftware\Util\Toolbox.cs:linje 383
at RotateImageTest.Program.RawTest() i C:\_gitProjects\ShooterSoftware\RotateImageTest\Program.cs:linje 24
at RotateImageTest.Program.Main(String[] args) i C:\_gitProjects\ShooterSoftware\RotateImageTest\Program.cs:linje 14
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
So there is one thing which might seem odd in my code, I am not getting the ExifProfile from the image that I have just loaded (image.GetExifProfile();) but from the exact same filepath (new ExifProfile(path);)The reason for this is that "image.GetExifProfile();" returns null which oddly enough is not the case with "new ExifProfile(path);".
Any help would be appreciated! Do not hesitate to ask me for more info if needed be.
Kind Regards,
Lorentzen1337