如何解决使用EXIF的图像方向
使用EXIF值的图像方向正常工作..但是在上传过程中,该图像不适用于其他图像。这是我的代码-
私有静态RotateFlipType GetOrientationToFlipType(int orientationValue) { RotateFlipTyperotateFlipType = RotateFlipType.RotateNoneFlipNone;
switch (orientationValue)
{
case 1:
rotateFlipType = RotateFlipType.RotateNoneFlipNone;
break;
case 2:
rotateFlipType = RotateFlipType.RotateNoneFlipX;
break;
case 3:
rotateFlipType = RotateFlipType.Rotate180FlipNone;
break;
case 4:
rotateFlipType = RotateFlipType.Rotate180FlipX;
break;
case 5:
rotateFlipType = RotateFlipType.Rotate90FlipX;
break;
case 6:
rotateFlipType = RotateFlipType.Rotate90FlipNone;
break;
case 7:
rotateFlipType = RotateFlipType.Rotate270FlipX;
break;
case 8:
rotateFlipType = RotateFlipType.Rotate270FlipNone;
break;
default:
rotateFlipType = RotateFlipType.RotateNoneFlipNone;
break;
}
return rotateFlipType;
}
受保护的无效btnSave_Click(对象发送者,EventArgs e) { 尝试 {
if (ProductCategoryPhoto.HasFile)
{
Stream ImagePaths = ProductCategoryPhoto.PostedFile.InputStream;
byte[] CustomerImagebytes = photoResige(650,650,ProductCategoryPhoto.PostedFile.InputStream);
string PhotoName = string.Empty;
string PhotoNameSmall = string.Empty;
string CID = Sessions.Name.EmployeeId.ToString();
string date = DateTime.Now.ToString("mm-dd-yyHHmmss");
PhotoName = CID + "-" + date + System.IO.Path.GetExtension(ProductCategoryPhoto.FileName).ToString().ToLower();
PhotoNameSmall = CID + "-" + date + "_prev" + System.IO.Path.GetExtension(ProductCategoryPhoto.FileName).ToString().ToLower();
string ext = Path.GetExtension(ProductCategoryPhoto.FileName);
//string smallImage = Server.MapPath("~/Images/ProjuctImg/" + PhotoNameSmall);
string bigImage = Server.MapPath("~/Images/ProjuctImg/" + PhotoName);
ProductCategoryPhoto.SaveAs(bigImage);
System.Drawing.Image obj;
Bitmap newimg;
Bitmap smallnewimg;
obj = System.Drawing.Image.FromFile(bigImage);
foreach (var prop in obj.PropertyItems)
{
if (prop.Id == 274) //value of EXIF
{
int orientationValue = obj.GetPropertyItem(prop.Id).Value[0];
RotateFlipType rotateFlipType = GetOrientationToFlipType(orientationValue);
obj.RotateFlip(rotateFlipType);
ImageFormat imgFormat = obj.RawFormat;
newimg = new Bitmap(obj,650);
//smallnewimg = new Bitmap(obj,120,120);
//obj.RemovePropertyItem(274);
//smallnewimg.Save(smallImage,imgFormat);
newimg.Save(bigImage,imgFormat);
break;
}
//else if (prop.Id != 274)
//{
// EncoderParameters encoderParameters = new EncoderParameters(1);
// System.Drawing.Image newImg1 = System.Drawing.Image.FromStream(ImagePaths,true,true);
// System.Drawing.Image image2 = photoResiges(650,(650 * newImg1.Width) / newImg1.Height,ProductCategoryPhoto.PostedFile.InputStream);
// encoderParameters.Param[0] = new EncoderParameter(Encoder.Compression,100);
// image2.Save(string.Concat(bigImage),ImageCodecInfo.GetImageEncoders()[1],encoderParameters);
//}
}
string PCName = tbxName.Text.Trim();
string ProductCategoryID = ddlCategoryID.SelectedValue.ToString() == "" ? "" : ddlCategoryID.SelectedValue.ToString();
string VatProfileCode = ddlVatProfile.SelectedValue.ToString() == "" ? "" : ddlVatProfile.SelectedValue.ToString();
string PCDescription = txtDescription.Text.Trim();
string st = objdalAdvertiseEntry.Product_Insert(Sessions.Name.UserId,PCName,PCDescription,CustomerImagebytes,PhotoName,ProductCategoryID,ddlUnitID.SelectedValue.ToString(),tbxProductCode.Text.Trim(),float.Parse(tbxProductAlert.Text.Trim() == "" ? "0" : tbxProductAlert.Text.Trim()),VatProfileCode,PhotoName);
GetProductUnitList();
if (st != null || st != "")
{
MessageController.Show(MessageCode.SaveSucceeded,MessageType.Confirmation,Page);
BindData();
ClearField();
}
else
{
MessageController.Show("তথ্য গুলো গ্রহণ করা সম্ভব হয়নি।",MessageType.Error,Page);
}
}
else
{
lblPhoto.Text = "ছবি দেয়া হয়নি ";
}
}
catch (Exception ex)
{
MessageController.Show("সংরক্ষণ ত্রুটি",Page);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。