I have the below code which is working as i expected (I think)
Can someone tell me how or what I'm suppose to return back, I understand its a byte of the image, but how do you get the new image after the orientation has been changed?
public byte[] ChangeImageOreintation(byte[] images)
{
var ms = new MemoryStream(images);
var originalImage = Image.FromStream(ms);
if (originalImage.PropertyIdList.Contains(0x0112))
{
int rotationValue = originalImage.GetPropertyItem(0x0112).Value[0];
switch (rotationValue)
{
case 1: // landscape, do nothing
break;
case 8: // rotated 90 right
// de-rotate:
originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate270FlipNone);
break;
case 3: // bottoms up
originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate180FlipNone);
break;
case 6: // rotated 90 left
originalImage.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);
break;
}
}
return images;
}
If the solution I have provided works for you, then please mark it as the answer!
You need to return the "originalImage" instance here. but this instance of type Image, so you need to change the method return type from byte[] to Image.
If you still need to return it in byte[] format, you need to convert this instance to byte[] .
You can take a look at this link on how to convert between those types.
Participant
1858 Points
1699 Posts
Change image Orientation
Dec 20, 2014 03:20 AM|Harrison.Scott|LINK
I have the below code which is working as i expected (I think)
Can someone tell me how or what I'm suppose to return back, I understand its a byte of the image, but how do you get the new image after the orientation has been changed?
All-Star
69271 Points
7975 Posts
Moderator
Re: Change image Orientation
Dec 20, 2014 06:08 AM|anas|LINK
You need to return the "originalImage" instance here. but this instance of type Image, so you need to change the method return type from byte[] to Image.
If you still need to return it in byte[] format, you need to convert this instance to byte[] .
You can take a look at this link on how to convert between those types.
http://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv