Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
C#
foreach (var prop in img.PropertyItems)
{
      if (prop.Id == 0x0112) //value of EXIF
      {
         var orientation = img.GetPropertyItem(prop.Id).Value[0];
         switch (orientation)
         {
            case 1:
            // No rotation required.
            break;
            case 2:
            img.RotateFlip(RotateFlipType.RotateNoneFlipX);
            break;
            case 3:
            img.RotateFlip(RotateFlipType.Rotate180FlipNone);


I have used above code to detect whether image orietation is changed from original. Suppose I have get orientation value as "3" and I want to set it to normal that is "1", so how I could replace that orientation property value 3 by 1?
Posted
Updated 7-Sep-15 23:23pm
v2

1 solution

Try it with Image.SetPropertyItem Method [^] like this:

C#
foreach (var prop in img.PropertyItems)
{
      if (prop.Id == 0x0112) //value of EXIF
      {
         var orientation = prop.Value;
         if (orientation == 3)
         {
             prop.Value[0] = 1;
             img.SetPropertyItem(prop);
         }
     }
}
 
Share this answer
 
v3
Comments
Kailas_ 8-Sep-15 6:07am    
Cannot implicitly convert type int to byte[] on following line, how to cast that..
prop.Value = 1;
Kailas_ 8-Sep-15 7:54am    
Thank, I did silly mistake..!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900