Пример #1
0
        protected void Upload(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string   uploadFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                FileInfo Finfo          = new FileInfo(FileUpload1.PostedFile.FileName);
                string   extension      = Finfo.Extension.ToLower();
                byte[]   data           = FileUpload1.FileBytes;
                byte[]   square;

                var sourceImage = CodeCarvings.Piczard.ImageArchiver.LoadImage(data);
                if (sourceImage.Size.Width == sourceImage.Size.Height)
                {
                    square = data;
                }
                else
                {
                    // Calculate the square size
                    int imageSize = sourceImage.Size.Width < sourceImage.Size.Height ? sourceImage.Size.Width : sourceImage.Size.Height;

                    // Get a fixed resize filter (square)
                    //var filter = new CodeCarvings.Piczard.FixedResizeConstraint(imageSize, imageSize);
                    var filter = new CodeCarvings.Piczard.FixedCropConstraint(imageSize, imageSize);
                    // Force white background
                    filter.CanvasColor = BackgroundColor.GetStatic(System.Drawing.Color.White);
                    square             = filter.SaveProcessedImageToByteArray(sourceImage, new CodeCarvings.Piczard.JpegFormatEncoderParams(82));
                }

                ParseFile file = new ParseFile("profile_picture" + extension, square);
                Task      t    = file.SaveAsync();
                t.Wait();

                theirPublicUserData.ProfilePic = file;
                Task t2 = theirPublicUserData.SaveAsync();
                t2.Wait();

                Image1.ImageUrl = theirPublicUserData.ProfilePic != null?theirPublicUserData.ProfilePic.Url.ToString() : "Images/default_prof_pic.png";
            }
        }