I was working on a asp.net web application to edit photos, such as rotate them or write information to the EXIF header. Magick.net works great, however, it doesn't work at all if an image is edited, such as rotated, with Windows Photo Viewer on Windows 7. I had to do this...
```
using (MemoryStream memStream = LoadMemoryStreamImage(uncPath))
{
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
foreach (ExifValue value in profile.Values)
{
if (value.Tag == ImageMagick.ExifTag.Software)
{
if (!value.ToString().StartsWith("Microsoft Windows Photo Viewer"))
{
profile.SetValue(ImageMagick.ExifTag.Copyright, txtPhotoBy.Text + ", Arkansas Geological Survey");
profile.SetValue(ImageMagick.ExifTag.ImageDescription, txtDescription.Text);
//double[] lat = { 33 / 1 , 42 / 1 , 10253 / 354 };
//profile.SetValue(ImageMagick.ExifTag.GPSLatitude, lat);
//profile.SetValue(ImageMagick.ExifTag.GPSLongitude, Convert.ToUInt32(-92.9594));
image.AddProfile(profile);
image.Write(uncPath);
}
}
}
}
}
bool microPhotoView = false;
using (MemoryStream memStream = LoadMemoryStreamImage(uncPath))
{
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
foreach (ExifValue value in profile.Values)
{
if (value.Tag == ImageMagick.ExifTag.Software)
{
//Determining if Photo has been edited/rotated with Microsoft Windows Photo Viewer
if (value.ToString().StartsWith("Microsoft Windows Photo Viewer"))
{
microPhotoView = true;
}
}
}
if (microPhotoView == false)
{
profile.SetValue(ImageMagick.ExifTag.ImageWidth, Convert.ToUInt32(imgHeight));
profile.SetValue(ImageMagick.ExifTag.ImageLength, Convert.ToUInt32(imgWidth));
image.AddProfile(profile);
image.Rotate(90);
image.Write(uncPath);
}
}
}
```
Comments: Resolved with changeset 37356: Fixed deadlock when writing a double that is infinity in the exif profile.
Added GetValue to ExifProfile and IptcProfile.
Renamed methods in ExifReader to match the enum.
```
using (MemoryStream memStream = LoadMemoryStreamImage(uncPath))
{
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
foreach (ExifValue value in profile.Values)
{
if (value.Tag == ImageMagick.ExifTag.Software)
{
if (!value.ToString().StartsWith("Microsoft Windows Photo Viewer"))
{
profile.SetValue(ImageMagick.ExifTag.Copyright, txtPhotoBy.Text + ", Arkansas Geological Survey");
profile.SetValue(ImageMagick.ExifTag.ImageDescription, txtDescription.Text);
//double[] lat = { 33 / 1 , 42 / 1 , 10253 / 354 };
//profile.SetValue(ImageMagick.ExifTag.GPSLatitude, lat);
//profile.SetValue(ImageMagick.ExifTag.GPSLongitude, Convert.ToUInt32(-92.9594));
image.AddProfile(profile);
image.Write(uncPath);
}
}
}
}
}
bool microPhotoView = false;
using (MemoryStream memStream = LoadMemoryStreamImage(uncPath))
{
using (MagickImage image = new MagickImage(memStream))
{
ExifProfile profile = image.GetExifProfile();
foreach (ExifValue value in profile.Values)
{
if (value.Tag == ImageMagick.ExifTag.Software)
{
//Determining if Photo has been edited/rotated with Microsoft Windows Photo Viewer
if (value.ToString().StartsWith("Microsoft Windows Photo Viewer"))
{
microPhotoView = true;
}
}
}
if (microPhotoView == false)
{
profile.SetValue(ImageMagick.ExifTag.ImageWidth, Convert.ToUInt32(imgHeight));
profile.SetValue(ImageMagick.ExifTag.ImageLength, Convert.ToUInt32(imgWidth));
image.AddProfile(profile);
image.Rotate(90);
image.Write(uncPath);
}
}
}
```
Comments: Resolved with changeset 37356: Fixed deadlock when writing a double that is infinity in the exif profile.
Added GetValue to ExifProfile and IptcProfile.
Renamed methods in ExifReader to match the enum.