-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from LazZiya/vNext
V next
- Loading branch information
Showing
6 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Linq; | ||
|
||
namespace LazZiya.ImageResize | ||
{ | ||
/// <summary> | ||
/// Image rotation operations | ||
/// </summary> | ||
public static class ImageRotation | ||
{ | ||
private const int exifOrientationId = 0x112; | ||
|
||
/// <summary> | ||
/// Keep resized image rotation as the original image | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="originalImage"></param> | ||
/// <returns></returns> | ||
public static Image ReserveOriginalRotation(this Image img, Image originalImage) | ||
{ | ||
if (!originalImage.PropertyIdList.Contains(exifOrientationId)) | ||
return img; | ||
|
||
var rotation = originalImage.GetPropertyItem(exifOrientationId); | ||
int val = BitConverter.ToUInt16(rotation.Value, 0); | ||
var rot = RotateFlipType.RotateNoneFlipNone; | ||
|
||
if (val == 3 || val == 4) | ||
rot = RotateFlipType.Rotate180FlipNone; | ||
else if (val == 5 || val == 6) | ||
rot = RotateFlipType.Rotate90FlipNone; | ||
else if (val == 7 || val == 8) | ||
rot = RotateFlipType.Rotate270FlipNone; | ||
|
||
if (val == 2 || val == 4 || val == 5 || val == 7) | ||
rot |= RotateFlipType.RotateNoneFlipX; | ||
|
||
if (rot != RotateFlipType.RotateNoneFlipNone) | ||
img.RotateFlip(rot); | ||
|
||
return img; | ||
} | ||
|
||
/// <summary> | ||
/// Rotate and/or flip the image | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="rotateFlipType"></param> | ||
/// <returns></returns> | ||
public static Image RotateFlipImage(this Image img, RotateFlipType rotateFlipType) | ||
{ | ||
img.RotateFlip(rotateFlipType); | ||
return img; | ||
} | ||
|
||
/// <summary> | ||
/// Rotate and/or flip the image | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="condition"></param> | ||
/// <param name="rotateFlipType"></param> | ||
/// <returns></returns> | ||
public static Image RotateFlipImageIf(this Image img, bool condition, RotateFlipType rotateFlipType) | ||
{ | ||
if(condition) | ||
img.RotateFlip(rotateFlipType); | ||
|
||
return img; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.