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: ** Comment from web user: dlemstra **
```
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: ** Comment from web user: dlemstra **
Can you be a bit more specific and explain what does not work means? Is it the rotate method that does not work? Or can you not modify the exif values? Are you getting any exceptions or just an unexpected output?
Can you attach a sample image I can use to reproduce the issue? Feel free to contact me through CodePlex if you don't want to publicly share your image.
p.s. Why do you load the image with 'LoadMemoryStreamImage'? Are you unable to load an image with an uncPath?