Bharani K

Bharani K

  • NA
  • 4
  • 1.5k

Image rotation in WPF Image control

Mar 26 2018 4:57 AM
Hello Team,
 
I have a problem related to image rotation
 
I have 2 images :
 
1.FabricHeaderExample.jpg
2.H12532D_ANTIBEE.jpg
 
For Example 1: FabricHeaderExample.jpg image looks Potraint image, when i upload this image and displaying in Image control.
 
while displaying it is rotating as landscape. It is having exif data. for this i write a code as below:
  1. Dim img As Image = Image.FromFile(selectedFileName)  
  2. Dim propid = (From p In img.PropertyItems Where p.Id = 274 Select p).ToList  
  3. If propid IsNot Nothing Then  
  4. For Each pid In propid  
  5. Dim orientationValue As Integer = pid.Value(0)  
  6. Dim rotateFlipType As RotateFlipType = OrientationToFlipType(orientationValue)  
  7. img.RotateFlip(rotateFlipType)  
  8. img.RemovePropertyItem(274)  
  9. Exit For  
  10. Next  
  11. End If  
  12. Private Shared Function OrientationToFlipType(ByVal orientation As StringAs RotateFlipType  
  13. Select Case Integer.Parse(orientation)  
  14. Case 1  
  15. Return RotateFlipType.RotateNoneFlipNone  
  16. Case 2  
  17. Return RotateFlipType.RotateNoneFlipX  
  18. Case 3  
  19. Return RotateFlipType.Rotate180FlipNone  
  20. Case 4  
  21. Return RotateFlipType.Rotate180FlipX  
  22. Case 5  
  23. Return RotateFlipType.Rotate90FlipX  
  24. Case 6  
  25. Return RotateFlipType.Rotate90FlipNone  
  26. Case 7  
  27. Return RotateFlipType.Rotate270FlipX  
  28. Case 8  
  29. Return RotateFlipType.Rotate270FlipNone  
  30. Case Else  
  31. Return RotateFlipType.RotateNoneFlipNone  
  32. End Select  
  33. End Function  
After that, it displaying properly.
 
For example 2: H12532D_ANTIBEE.jpg image looks normally image, but it is having exif data am using above code to display image in image control.
 
but the image is not rotating properly. but both images are getting same orientation value as 6.
I need to fix the code for both images are displaying properly.
Here am uploading sample application, in that application under images folder having above mentioned 2 images.

Answers (1)