What happened to this image cropper?

I create a tool for cropping images, and I can’t understand for life why it creates images that it produces ...

I follow the accepted answer here , but its still weird ... Here is my code:

public void Crop(
    string FileName,
    Crop Crop) {
    using (Bitmap Source = ((Bitmap)Image.FromFile(FileName))) {
        using (Bitmap Target = new Bitmap(Crop.Width, Crop.Height)) {
            using (Graphics Graphics = Graphics.FromImage(Target)) {
                Graphics.DrawImage(Source, new Rectangle(new Point(Crop.Left, Crop.Top), new Size(Crop.Width, Crop.Height)), new Rectangle(new Point(0, 0), new Size(Target.Width, Target.Height)), GraphicsUnit.Pixel);
            };

            Target.Save((FileName + ".temp"), JpegCodecInfo, HighQualityEncoder);
        };
    };


    this.NormalizeFileName(FileName);
}

Please help me. I am attaching an image of what I get ...alt text

UPDATE

For @Aaronontheweb, here is the class Cropand how it is populated:

public class Crop {
    [Required]
    public short Height { get; set; }

    [Required]
    public short Left { get; set; }

    [Required]
    public short Top { get; set; }

    [Required]
    public short Width { get; set; }
}

And jQuery that populates it:

$("#Image input:submit").bind("click", function () {
    $("#Crop\\.Height").val(Crop.height());
    $("#Crop\\.Left").val(Crop.position().left);
    $("#Crop\\.Top").val(Crop.position().top);
    $("#Crop\\.Width").val(Crop.width());
});

UPDATE 2

Nothing, I get it. I took a nap after I asked my question, only to clear my head, and when I looked at him again, I decided to switch two rectangles and see what happens. Well, guess what that fixed.

, , API, . , . , API , ?

+3
1

:

Graphics.DrawImage(, Rectangle ( (Crop.Left, Crop.Top), (Crop.Width, Crop.Height)), Rectangle ( (0, 0), (Target.Width, Target.Height)), GraphicsUnit.Pixel);

, Crop.Left Crop.Top 0, , . :

Graphics.DrawImage(, Rectangle ( (0,0), (Crop.Width, Crop.Height)), ( (0, 0), (Target.Width, Target.Height)), GraphicsUnit.Pixel);

+3

Source: https://habr.com/ru/post/1780153/


All Articles