コード例 #1
0
        private List <ImageForUpload> prepareImagesForUpload()
        {
            this.InvokeOnMainThread(delegate { nbUpload.TopItem.Title = "Preparing Images"; });

            List <ImageForUpload> list = new List <ImageForUpload>();

            int numberOfImages = listOfImagesToCheck.Count;

            int counter = 0;

            foreach (ImageForUpload imgToCheck in listOfImagesToCheck)
            {
                pauseEvent.WaitOne(Timeout.Infinite);
                if (stopEvent.WaitOne(0))
                {
                    return(null);
                }

                counter++;
                this.InvokeOnMainThread(delegate { lblPrepareImage.Text = "Preparing image " + counter + " of " + numberOfImages; });

                if (File.Exists(imgToCheck.filePath))
                {
                    ImageForUpload ifu = Graphics.CopyAndResizeFile(imgToCheck, imgToCheck.dealershipId);
                    if (ifu != null)
                    {
                        list.Add(ifu);
                    }
                }

                this.InvokeOnMainThread(delegate { pbPrepareImage.Progress = (float)counter / (float)numberOfImages; });
            }

            this.InvokeOnMainThread(delegate {
                lblPrepareImage.Text    = "Image Preparation Complete";
                pbPrepareImage.Progress = 100f;
                nbUpload.TopItem.Title  = "Start Uploading";
            });

            return(list);
        }
コード例 #2
0
        public static ImageForUpload CopyAndResizeFile(ImageForUpload ifu, int dealershipID)
        {
            string uploadFileDir  = System.IO.Path.Combine(GetImagePath(ifu.vehicleId), @"Uploads");
            string uploadFileName = Guid.NewGuid() + ".jpg";
            string uploadFilePath = Path.Combine(uploadFileDir, uploadFileName);

            if (!Directory.Exists(uploadFileDir))
            {
                Directory.CreateDirectory(uploadFileDir);
            }

            File.Copy(ifu.filePath, uploadFilePath, true);
            using (UIImage img = ResizeImage(UIImage.FromFile(uploadFilePath), 1600, 1200))
                img.AsJPEG().Save(uploadFilePath, true);

            GC.Collect();

            if (File.Exists(uploadFilePath))
            {
                if (ifu.damageId > 0)
                {
                    return new ImageForUpload()
                           {
                               vehicleId = ifu.vehicleId, dealershipId = dealershipID, filePath = uploadFilePath, fileSize = new FileInfo(uploadFilePath).Length, damageId = ifu.damageId
                           }
                }
                ;

                return(new ImageForUpload()
                {
                    vehicleId = ifu.vehicleId, dealershipId = dealershipID, fileNumber = ifu.fileNumber, filePath = uploadFilePath, fileSize = new FileInfo(uploadFilePath).Length, damageId = 0
                });
            }

            return(null);
        }