Pessoal to tentando usar o código abaixo, mas ontem mesmo numa selfie do iPhone, a foto saiu de ponta cabeça
private static Bitmap RotacaoImagem(HttpPostedFileBase file)
{
ImageConverter ic = new ImageConverter();
byte[] data;
using (Stream inputStream = file.InputStream)
{
using (MemoryStream ms = new MemoryStream())
{
inputStream.CopyTo(ms);
data = ms.ToArray();
}
}
Image img = (Image)ic.ConvertFrom(data);
Bitmap bmp2 = new Bitmap(img);
PropertyItem pi = bmp2.PropertyItems.Select(x => x).FirstOrDefault(x => x.Id == 0x0112);
pi = (PropertyItem)FormatterServices.GetUninitializedObject(typeof(PropertyItem));
pi.Id = 0x0112; // orientation
pi.Len = 2;
pi.Type = 3;
pi.Value = new byte[2] { 1, 0 };
pi.Value[0] = img.PropertyItems[0].Value.FirstOrDefault();
bmp2.SetPropertyItem(pi);
if (pi == null)
{
}
else
{
byte o = pi.Value[0];
if (o == 2) bmp2.RotateFlip(RotateFlipType.RotateNoneFlipX);
if (o == 3) bmp2.RotateFlip(RotateFlipType.RotateNoneFlipXY);
if (o == 4) bmp2.RotateFlip(RotateFlipType.RotateNoneFlipY);
if (o == 5) bmp2.RotateFlip(RotateFlipType.Rotate90FlipX);
if (o == 6) bmp2.RotateFlip(RotateFlipType.Rotate90FlipNone);
if (o == 7) bmp2.RotateFlip(RotateFlipType.Rotate90FlipY);
if (o == 8) bmp2.RotateFlip(RotateFlipType.Rotate90FlipXY);
}
return bmp2;
}
Junior Santana