来自 Ipad Air 图片的 GDI+ 中发生一般错误

A Generic error occurred in GDI+ from picture of Ipad Air

您好,我在尝试上传通过电子邮件从 Ipad 航空相机 (JPG)

下载的图片时出现此错误

在 GDI+

中发生一般错误

这是代码,谁能帮帮我?除了这张IpadAir.

所有图片都保存的很好
                var pic = System.Web.HttpContext.Current.Request.Files[0];// canvi per Vendor/fileuploadmaster
                Bitmap bmp = new Bitmap(pic.InputStream);
                DateTime dtaken;
                PropertyItem propItem;

                try {

                propItem = bmp.GetPropertyItem(36867);
                string sdate = System.Text.Encoding.UTF8.GetString(propItem.Value).Trim();
                string secondhalf = sdate.Substring(sdate.IndexOf(" "), (sdate.Length - sdate.IndexOf(" ")));
                string firsthalf = sdate.Substring(0, 10);
                firsthalf = firsthalf.Replace(":", "-");
                sdate = firsthalf + secondhalf;
                dtaken = DateTime.Parse(sdate);

                }
                catch {

                dtaken = DateTime.Now;

                }


                //Fecha de última modificacion
                //PropertyItem propItem = bmp.GetPropertyItem(306);


                var newFilePath = ConfigurationManager.AppSettings["PathTmpPhotos"].ToString();

                var FechaString = dtaken.ToString("yyMMddHHmmss");

                var newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + visitBrandId.ToString("D10") + "_" + FechaString + "_" + pic.FileName;
                var tmpFilePath = newFilePath + newFileName;

                pic.SaveAs(tmpFilePath);

                var img = FileUtilities.ResizePhoto(newFilePath, newFileName, 800, 600);

                ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);

                // Create an Encoder object based on the GUID
                // for the Quality parameter category.
                Encoder myEncoder = Encoder.Quality;

                // Create an EncoderParameters object.
                // An EncoderParameters object has an array of EncoderParameter
                // objects. In this case, there is only one
                // EncoderParameter object in the array.
                EncoderParameters myEncoderParameters = new EncoderParameters(1);

                // 0L = NO Quality // 100L = High Quality
                EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L);
                myEncoderParameters.Param[0] = myEncoderParameter;

                img.Save(Path.Combine(newFilePath, newFileName), jpgEncoder, myEncoderParameters);
                //img.Save(Path.Combine(newFilePath, newFileName));

解决方案在 ResizePhoto 中。

图片是手机拍的,尺寸小于800x600,所以这个功能无法将图片调整到更大的尺寸。

所以,解决方案是这样的:

var img = FileUtilities.ResizePhoto(newFilePath, newFileName, 300, 200);

因为没有手机拍的小于300x200的照片

此致