Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
HttpPostedFile hpf = context.Request.Files[i] as HttpPostedFile;
Image img = Image.FromStream(hpf.InputStream);

                try
                {
                    foreach (var prop in img.PropertyItems)
                    {
                        if (prop.Id == 0x0112) //value of EXIF
                        {
                            var orientation = img.GetPropertyItem(prop.Id).Value[0];
                            switch (orientation)
                            {
                                case 1:
                                    // No rotation required.
                                    break;
                                case 2:
                                    img.RotateFlip(RotateFlipType.RotateNoneFlipX);                                    
                                    break;
                                case 3:
                                    img.RotateFlip(RotateFlipType.Rotate180FlipNone);                                    
                                    break;
			   }
                            // This EXIF data is now invalid and should be removed.
                            img.RemovePropertyItem(0x0112);
                        }
                    }                   
                    
                }
                catch (Exception ex)
                {
                    string error = ex.Message.ToString();
                }

string strImageName = System.Web.HttpContext.Current.Request.QueryString["ID"].ToString() + "-" + strPhotoCounter + ".jpg";

//----------------This block works-------------

Image img_converted = (Image)img.Clone();
               img_converted.Save(strOriginalPath + strImageName);
               img_converted.Dispose();
               img.Dispose();

//---------------- But this is not------------------
		hpf.SaveAs(strOriginalPath + strImageName);
                img.Dispose();


It work if it done "Clone" but not with "HttpPostedFile.SaveAs" why this is so??
Posted
Updated 8-Sep-15 21:51pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900