答案 0 :(得分:2)
我通过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;
}
}
工作正常
答案 1 :(得分:0)
如果您在服务器上执行此操作,我建议您使用a server-safe wrapper而不是直接使用System.Drawing so you don't have to worry about avoiding the 29+ pitfalls and bugs。
我的ImageResizing.Net library offers both automatic and manual cropping
<强>自动强>
new ImageJob(source,dest,new
ResizeSettings("width=200;height=200;mode=crop;anchor=middlecenter")).Build();
手动(按百分比计算)
new ImageJob(source,dest,new
ResizeSettings("crop=20,20,80,80;cropxunits=100;cropyunits=100")).Build();
手动(在源图像坐标中)
new ImageJob(source,dest,new
ResizeSettings("crop=200,200,1000,1000;")).Build()