1

私は c# を使用して asp.net に取り組んでいます。その画像の一部を取得して画像を調整する必要があります。下の画像のように、画像の一部を中央からトリミングしたい。

ここに画像の説明を入力

誰でも私を助けてください。

4

2 に答える 2

1

Jqueryで画像の部分の座標を取得することでこれを行いました。

jQuery(function($) {
        $('#target').Jcrop({
            onChange: showCoords,
            onSelect: showCoords,
            onRelease: clearCoords
        });
    });
    function showCoords(c) {
        $('#xaxis').val(c.x);
        $('#yaxis').val(c.y);
        $('#x2').val(c.x2);
        $('#y2').val(c.y2);
        $('#xwidth').val(c.w);
        $('#div_width').val(c.w);
        $('#yheight').val(c.h);
        $('#div_height').val(c.h);
    };
    function clearCoords() {
        $('#coords input').val('0');
        $('#yheight').css({ color: 'red' });
        window.setTimeout(function() {
            $('#yheight').css({ color: 'inherit' });
        }, 500);
    };

次に、これらの座標を使用して、C#のように画像をトリミングしました

String savedFileName = uploadProfileImage(profileImageName, new System.Drawing.Rectangle(Int32.Parse(xaxis), Int32.Parse(yaxis), Int32.Parse(xwidth), Int32.Parse(yheight)));

public String uploadProfileImage(string profileImageName, System.Drawing.Rectangle rectangle)
    {
        try
        {
            String retFileName = "";
            if (profileImageName != null || profileImageName != "")
            {
                GenerateCroppedThumbNail(profileImageName, rectangle);
            }
            return retFileName;
        }
        catch (Exception)
        {
            return String.Empty;
        }
    }

それはうまくいきます

于 2013-04-03T07:19:48.100 に答える
0

If you're doing it on the server, I suggest using a server-safe wrapper instead of using System.Drawing directly, so you don't have to worry about avoiding the 29+ pitfalls and bugs.

My ImageResizing.Net library offers both automatic and manual cropping

Automatic

new ImageJob(source,dest,new 
 ResizeSettings("width=200;height=200;mode=crop;anchor=middlecenter")).Build();

Manual (by percentages)

new ImageJob(source,dest,new 
 ResizeSettings("crop=20,20,80,80;cropxunits=100;cropyunits=100")).Build();

Manual (in source image coordinates)

new ImageJob(source,dest,new 
 ResizeSettings("crop=200,200,1000,1000;")).Build()
于 2012-04-04T14:40:47.870 に答える