예제 #1
0
        private void timerImageAnimate_Tick(object sender, EventArgs e)
        {
            if (animationMoveIndex >= animationMovePoints.Length)
            {
                timerImageAnimate.Stop();

                if (imageSelectedIndex < totalImagesCount)
                {
                    AppearNextImage();
                    timerInputImageDrop.Start();
                }
                else
                {
                    GameEnd();
                }
            }
            else
            {
                this.pictureBoxInput.Location = animationMovePoints[animationMoveIndex++];

                pictureBoxInput.Image = ImageTransformation.ChangeOpacity(Image.FromFile(imagesInputPaths[imageSelectedIndex]), imageOpacity);

                imageOpacity = imageOpacity - .05f; // Changing Opacity
            }
        }
        public static void CreateHistogramImageAndSave(string sourceFilePath, byte[,] sourceImage, string imageCaption)
        {
            byte[,] resultImage = ImageTransformation.HistogramImage(sourceImage, 256);
            string newFilePath = ProbB.NewFilePath(sourceFilePath, $"HistogramImage{imageCaption}");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Histogram image created and saved to \'{newFilePath}\'");
        }
        public static void GammaCorrectionAndSave(string sourceFilePath, byte[,] sourceImage, double gammaValue)
        {
            byte[,] resultImage = ImageTransformation.GammaCorrection(sourceImage, gammaValue);
            string newFilePath = ProbB.NewFilePath(sourceFilePath, $"GammaCorrection-{gammaValue}");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Gamma correction (gamma: {gammaValue}) done and saved to \'{newFilePath}\'");
        }
        public static byte[,] HistogramEqualizationAndSave(string sourceFilePath, byte[,] sourceImage)
        {
            byte[,] resultImage = ImageTransformation.HistogramEqualization(sourceImage);
            string newFilePath = ProbB.NewFilePath(sourceFilePath, $"HistogramEqualization");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Histogram equalization done and saved to \'{newFilePath}\'");

            return(resultImage);
        }
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_201.jpg";

        // Get the image transformation class
        ImageTransformation imageTransformation = new ImageTransformation();
        imageTransformation.ResizeFactor = float.Parse(this.ddlResizeFactor.SelectedValue, System.Globalization.CultureInfo.InvariantCulture);

        // Process the image
        imageTransformation.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_201.jpg";

        // Get the image transformation class
        ImageTransformation imageTransformation = new ImageTransformation();

        imageTransformation.ResizeFactor = float.Parse(this.ddlResizeFactor.SelectedValue, System.Globalization.CultureInfo.InvariantCulture);

        // Process the image
        imageTransformation.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
예제 #7
0
    public async Task CompressImages(string path)
    {
        var log          = new List <string>();
        var compressions = new List <ImageTransformation>();

        Tinify.Key = tbTinyPngKey.Text;
        var isApiKeyValid = await Tinify.Validate();

        if (!isApiKeyValid)
        {
            log.Add("API key is invald: " + Tinify.Key);
        }
        else
        {
            var files = GetFiles(path).Take(5);
            // var files = GetFiles(path); //uncomment to optimize all files
            foreach (var img in files)
            {
                var sourcePath      = img.FilePath;
                var filename        = PathExtensions.GetRelativePath(path, sourcePath);
                var destinationPath = Path.Combine(DestinationFolderPath, filename);
                // ensure the folder exists for proper working source.ToFile();
                new DirectoryInfo(Path.GetDirectoryName(destinationPath)).Create();

                var compression = new ImageTransformation()
                {
                    Path    = destinationPath,
                    OldSize = img.Size,
                };

                var compressionsThisMonth = Tinify.CompressionCount == null ? 0 : Tinify.CompressionCount;
                if (compressionsThisMonth < 500)
                {
                    try
                    {
                        // Use the Tinify API client.
                        var source = Tinify.FromFile(sourcePath);
                        await source.ToFile(destinationPath);

                        compression.NewSize = source.GetResult().Result.Size;
                        compressions.Add(compression);
                    }
                    catch (AccountException e)
                    {
                        log.Add(string.Format("Error for image '{0}'. Error message: ", filename, e.Message));
                        //System.Console.WriteLine("The error message is: " + e.Message);
                        // Verify your API key and account limit.
                    }
                    catch (ClientException e)
                    {
                        log.Add(string.Format("Error for image '{0}'. Error message: ", filename, e.Message));
                        var mimetype = MimeTypes.getMimeFromFile(sourcePath);
                        log.Add(String.Format("The actual mime type of '{0}' image is '{1}' ", filename, mimetype));

                        // Check your source image and request options.
                    }
                    catch (ServerException e)
                    {
                        log.Add(string.Format("Error for image '{0}'. Error message: ", filename, e.Message));

                        // Temporary issue with the Tinify API.
                    }
                    catch (ConnectionException e)
                    {
                        log.Add(string.Format("Error for image '{0}'. Error message: ", filename, e.Message));

                        // A network connection error occurred.
                    }
                    catch (System.Exception e)
                    {
                        log.Add(string.Format("Error for image '{0}'. Error message: ", filename, e.Message));

                        // Something else went wrong, unrelated to the Tinify API.
                    }
                }
                else
                {
                    log.Add("Free API usage is near the limit: " + compressionsThisMonth);
                    //break;
                }
            }
        }

        using (TextWriter writer = new StreamWriter(Server.MapPath("~/errors.xml")))
        {
            var serializer = new XmlSerializer(typeof(List <string>));
            serializer.Serialize(writer, log);
        }

        using (TextWriter writer = new StreamWriter(Server.MapPath("~/compressions.xml")))
        {
            var serializer = new XmlSerializer(typeof(List <ImageTransformation>));
            serializer.Serialize(writer, compressions);
        }

        RadGrid1.DataSource = log;
        RadGrid1.DataBind();
    }
예제 #8
0
 public ImageTransformationTest()
 {
     _target = new ImageTransformation();
 }
예제 #9
0
    protected void DisplayUserState()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string crlf = "\r\n";

        #region UserState
        PictureTrimmerUserState userState = this.InlinePictureTrimmer1.UserState;

        #region Value
        PictureTrimmerValue value = userState.Value;

        #region ImageSelection
        ImageSelection imageSelection = value.ImageSelection;

        #region ImageTransformation
        ImageTransformation imageTransformation = imageSelection.Transformation;

        sb.Length = 0;
        sb.Append("Resize factor:" + imageTransformation.ResizeFactor.ToString(CultureInfo.InvariantCulture) + "%" + crlf);
        sb.Append("Rotation angle:" + imageTransformation.RotationAngle.ToString(CultureInfo.InvariantCulture) + "°" + crlf);
        sb.Append("Flip horizontal:" + (imageTransformation.FlipH ? "yes" : "no") + crlf);
        sb.Append("Flip vertical:" + (imageTransformation.FlipV ? "yes" : "no") + crlf);
        this.txtUserState_Value_ImageSelection_Transformation.Text = sb.ToString();
        #endregion

        #region ImageCrop
        ImageCrop imageCrop = imageSelection.Crop;

        sb.Length = 0;
        sb.Append("Rectangle:" + (imageCrop.Rectangle.HasValue ? imageCrop.Rectangle.Value.ToString() : "Auto") + crlf);
        // Note: in this example imageCrop.CanvasColor is not displayed.
        this.txtUserState_Value_ImageSelection_Crop.Text = sb.ToString();
        #endregion

        #endregion

        #region ImageAdjustments
        ImageAdjustmentsFilter imageAdjustments = value.ImageAdjustments;

        sb.Length = 0;
        sb.Append("Brightness:" + imageAdjustments.Brightness.ToString(CultureInfo.InvariantCulture) + crlf);
        sb.Append("Contrast:" + imageAdjustments.Contrast.ToString(CultureInfo.InvariantCulture) + crlf);
        sb.Append("Hue:" + imageAdjustments.Hue.ToString(CultureInfo.InvariantCulture) + "°" + crlf);
        sb.Append("Saturation:" + imageAdjustments.Saturation.ToString(CultureInfo.InvariantCulture) + crlf);
        this.txtUserState_Value_ImageAdjustments.Text = sb.ToString();
        #endregion

        // Note: In this example value.ImageBackColorApplyMode is not displayed.

        #endregion

        #region UIParams
        PictureTrimmerUIParams uiParams = userState.UIParams;

        sb.Length = 0;
        sb.Append("Zoom factor:" + (uiParams.ZoomFactor.HasValue ? uiParams.ZoomFactor.Value.ToString(CultureInfo.InvariantCulture) + "%" : "auto") + crlf);
        sb.Append("Picture scroll horizontal:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollH.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf);
        sb.Append("Picture scroll vertical:" + (uiParams.PictureScrollH.HasValue ? uiParams.PictureScrollV.Value.ToString(CultureInfo.InvariantCulture) : "auto") + crlf);
        sb.Append("Command panel scroll vertical:" + uiParams.CommandPanelScrollV.ToString(CultureInfo.InvariantCulture) + crlf);
        this.txtUserState_UIParams.Text = sb.ToString();

        #endregion

        #endregion
    }
        public ActionResult CreatePublication(CreatePublicationModel publicationView)
        {
            Publication publication = new Publication();

            publication.ToCreatePublicationModel(publicationView);
            if (db.Publications.Where(m => m.Id == publicationView.Id).FirstOrDefault() == null)
            {
                publication = db.Publications.Add(publication);
                db.SaveChanges();
            }
            else
            {
                publication = db.Publications.Where(m => m.Id == publicationView.Id).FirstOrDefault();
                publication.ToCreatePublicationModel(publicationView);

                publication.IsApprovedByAdmin = false;
                publication.IsActive          = false;
                db.Entry(publication).State   = EntityState.Modified;
                db.SaveChanges();
            }
            int count;

            try
            {
                count = Directory.EnumerateFiles(Server.MapPath("~/Images/Publication/" + publication.Id + "/")).Count() + 1;
            }
            catch
            {
                count = 1;
            }
            foreach (var file in publicationView.Files)
            {
                if (file != null)
                {
                    try
                    {
                        System.IO.File.WriteAllBytes(Server.MapPath("~/Images/Publication/" + publication.Id + "/" + count + ".jpg"), ImageTransformation.Transform(file));
                    }
                    catch (IOException e)
                    {
                        Directory.CreateDirectory(Server.MapPath("~") + "/Images/Publication/" + publication.Id);
                        System.IO.File.WriteAllBytes(Server.MapPath("~/Images/Publication/" + publication.Id + "/" + count + ".jpg"), ImageTransformation.Transform(file));
                    }
                    count++;
                }
            }
            return(RedirectToAction("MyPublications"));
        }