Пример #1
0
        public void Read_DataIsMinimal_ReturnsEmptyCollection()
        {
            var reader = new ExifReader(new byte[] { 69, 120, 105, 102, 0, 0 });

            IList <IExifValue> result = reader.ReadValues();

            Assert.Equal(0, result.Count);
        }
Пример #2
0
            public void ShouldReturnEmptyCollectionWhenDataHasNoValues()
            {
                var data = new byte[] { 69, 120, 105, 102, 0, 0 };

                var result = ExifReader.Read(data);

                Assert.Empty(result.Values);
            }
Пример #3
0
        public void Read_DataIsEmpty_ReturnsEmptyCollection()
        {
            var reader = new ExifReader(new byte[] { });

            IList <ExifValue> result = reader.ReadValues();

            Assert.Equal(0, result.Count);
        }
Пример #4
0
        public void Read_DataIsEmpty_ReturnsEmptyCollection()
        {
            var reader = new ExifReader(Array.Empty <byte>());

            IList <IExifValue> result = reader.ReadValues();

            Assert.Equal(0, result.Count);
        }
Пример #5
0
            public void ShouldReturnEmptyCollectionWhenDataIsEmpty()
            {
                var data = new byte[] { };

                var result = ExifReader.Read(data);

                Assert.Empty(result.Values);
            }
Пример #6
0
        static void ProcessImage(string image, string outpath)
        {
            var timage = image;

            try {
                DateTime datePicture = DateTime.MinValue;
                try {
                    using (ExifReader reader = new ExifReader(timage)) {
                        DateTime datePictureTaken;
                        if (reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken))
                        {
                            datePicture = datePictureTaken;
                        }
                    }
                }
                catch (Exception) {
                }
                if (datePicture.Equals(DateTime.MinValue))
                {
                    var date = File.GetLastWriteTime(timage);
                    Console.WriteLine("Can't determine date. " + timage + " Use file date: ( " + date.ToShortDateString() + " - " + date.ToShortTimeString() + " ) ? (y/n)");
                    if (Console.ReadKey().KeyChar.ToString().ToUpper().Equals("Y"))
                    {
                        datePicture = date;
                        Encoding _Encoding = Encoding.UTF8;
                        Image    theImage  = new Bitmap(image);
                        // 36867 = DateTimeOriginal
                        // 36868 = DateTimeDigitized
                        PropertyItem prop = theImage.PropertyItems[0];
                        SetProperty(ref prop, 36868, date.ToString("yyyy:MM:dd HH:mm:ss"));
                        theImage.SetPropertyItem(prop);
                        theImage.Save(timage + ".tmp");
                        timage = timage + ".tmp";
                    }
                }
                if (!datePicture.Equals(DateTime.MinValue))
                {
                    int i = 1;
                    while (File.Exists(DateToFile(outpath, datePicture, i)))
                    {
                        i++;
                    }
                    //Console.WriteLine(DateToFile(outpath, datePicture, i));
                    if (!Directory.Exists(DateToYear(outpath, datePicture)))
                    {
                        Directory.CreateDirectory(DateToYear(outpath, datePicture));
                    }
                    if (!Directory.Exists(DateToYearMonth(outpath, datePicture)))
                    {
                        Directory.CreateDirectory(DateToYearMonth(outpath, datePicture));
                    }
                    File.Move(timage, DateToFile(outpath, datePicture, i));
                }
            }
            catch (Exception e) {
                Console.WriteLine(timage + ": " + e.Message);
            }
        }
Пример #7
0
        public async Task <IActionResult> AddFile(IFormFile file)
        {
            if (file != null)
            {
                // путь к папке Files
                User usr = await _userManager.FindByEmailAsync(User.Identity.Name);

                string fileName = usr.Email + "_avatar";
                string path     = "/photos/" + fileName + ".png";
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    file.CopyTo(fileStream);
                }
                usr.Photo = path;

                var pc = new PhotoCoordinatesModel();
                try{
                    using (var reader = new ExifReader(_appEnvironment.WebRootPath + path))
                    {
                        pc.Lat = reader.GetLatitude();
                        pc.Lon = reader.GetLongitude();
                    }
                    double lat = 0, lon = 0;
                    if (pc.Lat.HasValue)
                    {
                        lat = pc.Lat.Value;
                    }
                    else
                    {
                        await _userManager.UpdateAsync(usr);

                        return(RedirectToAction("Profile", "Account"));
                    }
                    if (pc.Lon.HasValue)
                    {
                        lon = pc.Lon.Value;
                    }
                    else
                    {
                        await _userManager.UpdateAsync(usr);

                        return(RedirectToAction("Profile", "Account"));
                    }
                    usr.PhotoLon = lon;
                    usr.PhotoLat = lat;
                    //Console.WriteLine(GetAddress(pc.Lat, pc.Lon));
                }
                catch (ExifLibException exifex)
                {
                    pc.Error = exifex.Message;
                }

                await _userManager.UpdateAsync(usr);
            }

            return(RedirectToAction("Profile", "Account"));
        }
Пример #8
0
            public void ShouldReturnEmptyCollectionWhenDataHasNoValues()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0 };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
            }
Пример #9
0
            public void ShouldReturnEmptyCollectionWhenDataIsEmpty()
            {
                var reader = new ExifReader();
                var data   = new byte[] { };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
            }
Пример #10
0
        private static void ReadExifString(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta)
        {
            string str;

            if (reader.GetTagValue(tag, out str))
            {
                meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), 0.0f, str));
            }
        }
Пример #11
0
        private static void ReadExifLong(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta)
        {
            UInt32 num;

            if (reader.GetTagValue(tag, out num))
            {
                meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), (float)num, num.ToString()));
            }
        }
Пример #12
0
 private static void ReadExifRational(ExifReader reader, ExifTags tag, ref List <GLTextureStream.ImageMetaData> meta)
 {
     int[] rational;
     if (reader.GetTagValue(tag, out rational))
     {
         float value = (float)rational[0] / (float)rational[1];
         meta.Add(new GLTextureStream.ImageMetaData(tag.ToString(), value, value.ToString()));
     }
 }
Пример #13
0
            public void ShouldCheckArraySize()
            {
                var data = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 148, 1, 1, 0, 255, 255, 255, 255, 26, 0, 0, 0, 31, 0, 0, 0, 42 };

                var result = ExifReader.Read(data);

                Assert.Empty(result.Values);
                Assert.Single(result.InvalidTags);
            }
Пример #14
0
        public void Read_DataIsEmpty_ReturnsEmptyCollection()
        {
            var reader = new ExifReader();
            var data   = new byte[] { };

            var result = reader.Read(data);

            Assert.AreEqual(0, result.Count);
        }
Пример #15
0
        private async Task <string[]> ResizeAsync(string filePath)
        {
            var str = new string[2];

            string folder = Path.GetDirectoryName(filePath) + "/";
            string img    = folder + "R" + Path.GetFileName(filePath);
            string thumb  = folder + "T" + Path.GetFileName(filePath);

            IFile vf = await FileSystem.Current.GetFileFromPathAsync(filePath);

            using (Stream stream = await vf.OpenAsync(PCLStorage.FileAccess.Read))
            {
                JpegInfo exif = ExifReader.ReadJpeg(stream);

                int width      = 0;
                int height     = 0;
                int thumbWidth = 0;
                int thumbHigh  = 0;

                if (exif.Width > 0)
                {
                    width  = exif.Width;
                    height = exif.Height;
                    if (width > height)
                    {
                        var temp = width;
                        width  = height;
                        height = temp;

                        _landscape = true;
                    }
                }
                else
                {
                    width  = 1000;
                    height = 2000;
                }
                if (exif.Width / 7 < 100)
                {
                    thumbWidth = 70;
                    thumbHigh  = 100;
                }
                else
                {
                    thumbWidth = width / 7;
                    thumbHigh  = height / 13;
                }

                _imageService.ResizeImage(filePath, img, width, height);
                _imageService.ResizeImage(filePath, thumb, thumbWidth, thumbHigh);

                str[0] = img;
                str[1] = thumb;
            }

            return(str);
        }
Пример #16
0
            public void ShouldReturnEmptyCollectionWhenDataIsEmpty()
            {
                var reader = new ExifReader();
                var data   = new byte[] { };

                reader.Read(data);

                Assert.AreEqual(0, reader.Values.Count);
            }
Пример #17
0
            public void ShouldBeAbleToReadEmptyStrings()
            {
                var data = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 14, 1, 2, 0, 0, 0, 0, 0, 32, 0, 0, 0, 26, 0, 0, 0, 0, 0 };

                var result = ExifReader.Read(data);

                Assert.Single(result.Values);
                Assert.Equal(string.Empty, result.Values.First().GetValue());
            }
Пример #18
0
            public void ShouldCheckTypeOfJPEGInterchangeFormatLength()
            {
                var data = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0 };

                var result = ExifReader.Read(data);

                Assert.Empty(result.Values);
                Assert.Equal(2, result.InvalidTags.Count);
            }
Пример #19
0
            public void ShouldReturnEmptyCollectionWhenDataHasNoValues()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0 };

                reader.Read(data);

                Assert.AreEqual(0, reader.Values.Count);
            }
Пример #20
0
        public void Read_DataIsMinimal_ReturnsEmptyCollection()
        {
            var reader = new ExifReader();
            var data   = new byte[] { 69, 120, 105, 102, 0, 0 };

            var result = reader.Read(data);

            Assert.AreEqual(0, result.Count);
        }
Пример #21
0
        private static void ExtractTag <T>(ExifReader reader, Dictionary <string, object> info, ExifTags tag)
        {
            T tagVal;

            if (reader.GetTagValue <T>(tag, out tagVal))
            {
                info.Add(tag.ToString(), tagVal.ToString());
            }
        }
Пример #22
0
        private static bool AreEquals(string filepath1, string filepath2)
        {
            FileInfo fi1 = new FileInfo(filepath1);
            FileInfo fi2 = new FileInfo(filepath2);
            DateTime dateTaken1, dateTaken2;
            string   make1, make2, model1, model2;
            object   exposure1, exposure2,
                     fNumber1, fNumber2,
                     focalL1, focalL2,
                     PixelXDimension1, PixelXDimension2,
                     PixelYDimension1, PixelYDimension2,
                     PhotographicSensitivity1, PhotographicSensitivity2;

            if (fi1.Length == fi2.Length)
            {
                using (ExifReader reader = new ExifReader(filepath1))
                {
                    reader.GetTagValue(ExifTags.DateTimeOriginal, out dateTaken1);
                    reader.GetTagValue(ExifTags.Make, out make1);
                    reader.GetTagValue(ExifTags.Model, out model1);
                    reader.GetTagValue(ExifTags.ExposureTime, out exposure1);
                    reader.GetTagValue(ExifTags.FNumber, out fNumber1);
                    reader.GetTagValue(ExifTags.FocalLength, out focalL1);
                    reader.GetTagValue(ExifTags.PixelXDimension, out PixelXDimension1);
                    reader.GetTagValue(ExifTags.PixelYDimension, out PixelYDimension1);
                    reader.GetTagValue(ExifTags.PhotographicSensitivity, out PhotographicSensitivity1);
                }

                using (ExifReader reader = new ExifReader(filepath2))
                {
                    reader.GetTagValue(ExifTags.DateTimeOriginal, out dateTaken2);
                    reader.GetTagValue(ExifTags.Make, out make2);
                    reader.GetTagValue(ExifTags.Model, out model2);
                    reader.GetTagValue(ExifTags.ExposureTime, out exposure2);
                    reader.GetTagValue(ExifTags.FNumber, out fNumber2);
                    reader.GetTagValue(ExifTags.FocalLength, out focalL2);
                    reader.GetTagValue(ExifTags.PixelXDimension, out PixelXDimension2);
                    reader.GetTagValue(ExifTags.PixelYDimension, out PixelYDimension2);
                    reader.GetTagValue(ExifTags.PhotographicSensitivity, out PhotographicSensitivity2);
                }

                if (dateTaken1 == dateTaken2 &&
                    make1 == make2 &&
                    model1 == model2 &&
                    exposure1?.ToString() == exposure2?.ToString() &&
                    fNumber1?.ToString() == fNumber2?.ToString() &&
                    focalL1?.ToString() == focalL2?.ToString() &&
                    PixelXDimension1?.ToString() == PixelXDimension2?.ToString() &&
                    PixelYDimension1?.ToString() == PixelYDimension2?.ToString() &&
                    PhotographicSensitivity1?.ToString() == PhotographicSensitivity2?.ToString())
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #23
0
        public async Task <IActionResult> Create([Bind("Id,Date,Path,UserId,Photo")] PhotoCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                var    currentUser    = await GetCurrentUserAsync();

                string filePath = null;

                if (model.Photo != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        model.Photo.CopyTo(fileStream);
                    }
                }

                Photo photo = new Photo
                {
                    Path   = uniqueFileName,
                    UserId = currentUser.Id
                };

                try
                {
                    using (ExifReader reader = new ExifReader(filePath))
                    {
                        DateTime dateTime;
                        if (reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out dateTime))
                        {
                            photo.Date = dateTime;
                        }
                    }
                }
                catch (ExifLibException)
                {
                }

                _context.Add(photo);
                await _context.SaveChangesAsync();

                // Redirect to edit view for photo being created
                return(RedirectToAction("Edit", new { id = photo.Id }));
            }
            return(View(model));
        }
Пример #24
0
    public static void Main(String[] Args)
    {
        if (Args.Length != 1)
        {
            Console.WriteLine("Usage: ExifReader <path to image>");
            Environment.Exit(-1);
        }

        String file = Args[0];

        ExifReader r = new ExifReader(file);  //file is String

        Console.WriteLine("");
        r.PrintAll();
        Console.WriteLine("");
        Console.WriteLine("Make: " + r.GetMake());
        Console.WriteLine("Model: " + r.GetModel());

        Console.WriteLine("White Balance: " + r.GetWhiteBalance());
        // User this one for FStop
        Console.WriteLine("F" + r.GetFNumber());
        // Use this one for Shutter Speed
        Console.WriteLine("Exposure Time: " + r.GetExposureTime() + " Sec");
        Console.WriteLine("Exposure Program: " + r.GetExposureProgram());
        Console.WriteLine("ISO: " + r.GetISO());
        Console.WriteLine("Exposure Bias Value: " + r.GetExposureBiasValue());
        Console.WriteLine("Subject Distance: " + r.GetSubjectDistance());
        Console.WriteLine("FocalLength: " + r.GetFocalLength());

        Console.WriteLine("Flash: " + r.GetFlash());
        Console.WriteLine("Exposure Mode: " + r.GetExposureMode());
        Console.WriteLine("EXIF Version: " + r.GetExifVersion());
        Console.WriteLine("DateTime: " + r.GetDateTime());
        Console.WriteLine("DateTimeOriginal: " + r.GetDateTimeOriginal());
        Console.WriteLine("Artist: " + r.GetArtist());
        Console.WriteLine("Copyright: " + r.GetCopyright());
        Console.WriteLine("Software: " + r.GetSoftware());
        Console.WriteLine("SpectralSensitivity: " + r.GetSpectralSensitivity());
        Console.WriteLine("DateTimeDigitized: " + r.GetDateTimeDigitized());
        Console.WriteLine("ImageWidth: " + r.GetImageWidth());
        Console.WriteLine("ImageLength: " + r.GetImageLength());
        Console.WriteLine("BitsPerSample: " + r.GetBitsPerSample());
        Console.WriteLine("Compression: " + r.GetCompression());
        Console.WriteLine("Orientation: " + r.GetOrientation());
        Console.WriteLine("SubjectArea: " + r.GetSubjectArea());
        Console.WriteLine("SubjectLocation: " + r.GetSubjectLocation());
        Console.WriteLine("FocalLengthIn35mmFilm: " + r.GetFocalLengthIn35mmFilm());
        Console.WriteLine("Contrast: " + r.GetContrast());
        Console.WriteLine("Saturation: " + r.GetSaturation());
        Console.WriteLine("Sharpness: " + r.GetSharpness());
        Console.WriteLine("SubjectDistanceRange: " + r.GetSubjectDistanceRange());
        Console.WriteLine("MeteringMode: " + r.GetMeteringMode());
        Console.WriteLine("DigitalZoomRatio: " + r.GetDigitalZoomRatio());
        Console.WriteLine("ImageUniqueID: " + r.GetImageUniqueID());
        //Console.WriteLine(": " + r.Get());
    }
Пример #25
0
        private static void AssertStringValue(ExifReader reader, ExifTags tag, string expected)
        {
            string actual;

            if (!reader.GetTagValue(tag, out actual))
            {
                Assert.Fail("Tag '{0}' not found.", tag);
            }
            Assert.AreEqual(expected, actual, "Tag '{0}' value mismatch.");
        }
 public static DateTime ExifDate(string fname)
 {
     using (ExifReader reader = new ExifReader(fname))
     {
         // Extract the tag data using the ExifTags enumeration
         DateTime datePictureTaken = System.DateTime.Now;
         reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken);
         return(datePictureTaken);
     }
 }
Пример #27
0
        public async Task <IEnumerable <Tag> > GetTagsAsync(string srcPath)
        {
            VerifySourceFile(srcPath);

            var reader   = new ExifReader(_opts);
            var parser   = new ExifParser();
            var exifJson = await reader.ReadExifAsync(srcPath).ConfigureAwait(false);

            return(parser.ParseTags(exifJson));
        }
Пример #28
0
            public void ShouldBeAbleToReadEmptyStrings()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 14, 1, 2, 0, 0, 0, 0, 0, 32, 0, 0, 0, 26, 0, 0, 0, 0, 0 };

                reader.Read(data);

                Assert.AreEqual(1, reader.Values.Count);
                Assert.AreEqual(string.Empty, reader.Values.First().GetValue());
            }
Пример #29
0
            public void ShouldCheckTypeOfJPEGInterchangeFormatLength()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0 };

                reader.Read(data);

                Assert.AreEqual(0, reader.Values.Count);
                Assert.AreEqual(2, reader.InvalidTags.Count);
            }
Пример #30
0
            public void ShouldCheckArraySize()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 148, 1, 1, 0, 255, 255, 255, 255, 26, 0, 0, 0, 31, 0, 0, 0, 42 };

                reader.Read(data);

                Assert.AreEqual(0, reader.Values.Count);
                Assert.AreEqual(1, reader.InvalidTags.Count());
            }
Пример #31
0
    private void InitializeValues()
    {
      if (_Values != null)
        return;

      if (Data == null)
      {
        _Values = new Collection<ExifValue>();
        return;
      }

      ExifReader reader = new ExifReader();
      _Values = reader.Read(Data);
      _InvalidTags = new List<ExifTag>(reader.InvalidTags);
      _ThumbnailOffset = reader.ThumbnailOffset;
      _ThumbnailLength = reader.ThumbnailLength;
    }
        /// <summary>
        /// Uploads a given file using whole-file upload OR partial file upload, base on the need
        /// </summary>
        /// <param name="context">The HTTP Context</param>
        /// <param name="postedFile">The posted file</param>
        /// <param name="fileName">The destination file name</param>
        /// <param name="fileType">The file type</param>
        /// <param name="fileSize">The file size</param>
        /// <param name="contentRange">The total content range</param>
        /// <returns>Transportable data about the uploaded file</returns>
        protected virtual TransportableUploadedFile UploadFile(HttpContext context, HttpPostedFile postedFile, string fileName, string fileType, long fileSize, string[] contentRange)
        {
            //-------------------------------------------
            //  Init
            //-------------------------------------------
            fileName = this.FormatFileName(context, fileName, fileType);
            string errorMessage;
            Bitmap bitmap = null;

            //-------------------------------------------
            //  The image is valid?
            //-------------------------------------------
            if (this.ValidateUploadedFile(context, postedFile, fileName, fileType, fileSize, out errorMessage))
            {
                //-------------------------------------------
                //  Create the image uploads directory in case it's not exists
                //-------------------------------------------
                if (!Directory.Exists(this.UploadsDirectoryPath))
                {
                    Directory.CreateDirectory(this.UploadsDirectoryPath);
                }

                //-------------------------------------------
                //  Deletermine the file full path and if we're using multipart upload
                //-------------------------------------------
                string filePath = this.CombineUploadsPathAndFileName(context, fileName);
                bool isPartialUpload = (contentRange != null && File.Exists(filePath)
                    && fileSize > new FileInfo(filePath).Length);

                if (isPartialUpload)
                {
                    //  We're executing a multipart uploading
                    this.SavePartialUploadedFile(context, postedFile.InputStream, filePath);
                }
                else
                {
                    //  We're uploading the whole file
                    this.SaveUploadedFile(context, postedFile, filePath);

                    //  Run uploaded file event
                    this.OnFileUploaded(context, postedFile, filePath);
                }

                if (fileSize == this.GetFileSize(context, filePath))
                {
                    //-------------------------------------------
                    //  If we got JPG, we can rotate the image based on the
                    //  image EXIF data
                    //-------------------------------------------
                    if ((fileType == "image/jpg" || fileType == "image/jpeg"))
                    {
                        ExifReader reader = null;
                        try
                        {
                            using (bitmap = new Bitmap(filePath))
                            {
                                if (fileType == "image/jpg" || fileType == "image/jpeg")
                                {
                                    using (reader = new ExifReader(filePath))
                                    {
                                        int orientation = 0;
                                        if (reader.GetTagValue(ExifTags.Orientation, out orientation))
                                        {
                                            switch (orientation)
                                            {
                                                case 3:
                                                    bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
                                                    break;
                                                case 6:
                                                    bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                                                    break;
                                                case 8:
                                                    bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                                                    break;
                                                default:
                                                    throw new ArgumentException("The given orientation is not valid (" + orientation + ")", "orientation");
                                            }
                                        }
                                    }
                                }
                            }

                            /* Move it back */
                            File.Delete(filePath);
                            File.Move(filePath + ".tmp", filePath);
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            if (bitmap != null)
                            {
                                bitmap.Dispose();
                                bitmap = null;
                            }

                            if (reader != null)
                            {
                                reader.Dispose();
                                reader = null;
                            }
                        }
                    }

                    //-------------------------------------------
                    //  Resize the image?
                    //-------------------------------------------

                    try
                    {
                        bool shouldResizeImage = false;
                        if (this.AllowHighQualityImagesConvertion)
                        {
                            using (bitmap = new Bitmap(filePath))
                            {
                                shouldResizeImage = this.ResizeImageActionMaximumWidth > -1 && this.ResizeImageActionMaximumHeight > -1
                                        && (this.ResizeImageActionMaximumWidth < bitmap.Width || this.ResizeImageActionMaximumHeight < bitmap.Height);

                                /* Should we resize this image? */
                                if (shouldResizeImage)
                                {
                                    /* Resize the image and save it as high-quality image */
                                    dynamic result = this.ScaleImage(context, bitmap, this.ResizeImageActionMaximumWidth, this.ResizeImageActionMaximumHeight);
                                    using (Bitmap resizedBitmap = ResizeImage(bitmap, result.Width, result.Height))
                                    {
                                        SaveJpeg(filePath + ".tmp", resizedBitmap, this.HighQualityImageLevel);
                                    }
                                }
                                else
                                {
                                    /* Since we've requested to save the image as high-quality
                                     * we'll just do so */
                                    SaveJpeg(filePath + ".tmp", bitmap, this.HighQualityImageLevel);
                                }
                            }

                            File.Delete(filePath);
                            File.Move(filePath + ".tmp", filePath);
                        }
                        else
                        {
                            using (bitmap = new Bitmap(filePath))
                            {
                                /* Just resize the image if we need to */
                                shouldResizeImage = this.ResizeImageActionMaximumWidth > -1 && this.ResizeImageActionMaximumHeight > -1
                                        && (this.ResizeImageActionMaximumWidth < bitmap.Width || this.ResizeImageActionMaximumHeight < bitmap.Height);

                                if (shouldResizeImage)
                                {
                                    dynamic result = this.ScaleImage(context, bitmap, this.ResizeImageActionMaximumWidth, this.ResizeImageActionMaximumHeight);
                                    using (Graphics graphics = Graphics.FromImage(result))
                                    {
                                        //draw the image into the target bitmap
                                        graphics.DrawImage(bitmap, 0, 0, result.Width, result.Height);
                                    }

                                    bitmap.Save(filePath + ".tmp");
                                }
                            }

                            if (shouldResizeImage)
                            {
                                File.Delete(filePath);
                                File.Move(filePath + ".tmp", filePath);
                            }
                        }
                    }
                    finally
                    {
                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                            bitmap = null;
                        }
                    }

                    //-------------------------------------------
                    //  Call event
                    //-------------------------------------------
                    this.OnUploadWholeFileCompleted(context, new FileInfo(filePath));
                }
                else if (this.DiscardAbortedUploads && contentRange == null)
                {
                    //  We got abroted file, remove it
                    File.Delete(filePath);
                    errorMessage = "FileUploadAbroted";
                }
            }

            return new TransportableUploadedFile(context, this, fileName, fileSize, errorMessage);
        }