【发布时间】:2016-10-27 00:38:18
【问题描述】:
您好,我想裁剪图像并将其上传到服务器上。
我正在使用 croppie js 插件并使用 get() 方法通过 WebImage 类获取点以在服务器上对其进行裁剪。
Asp.net MVC 代码
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ImageCrop(FormCollection fc)
{
WebImage data = WebImage.GetImageFromRequest();
if (data != null)
{
int x1, y1, x2, y2;
x1 = int.Parse(fc["x1"].ToString());
y1 = int.Parse(fc["y1"].ToString());
x2 = int.Parse(fc["x2"].ToString());
y2 = int.Parse(fc["y2"].ToString());
var fileName = Path.GetFileName(data.FileName);
fileName = Lawyer_id2 + ".jpeg";
var big = Server.MapPath("~/contents/ProfilePictures/big/" + fileName);
data.Crop(y1, x1, x2, y2);
data.Save(big);
}
}
JS代码
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 200,
height: 200,
type: 'square'
},
boundary: {
width: 300,
height: 300
},
showZoomer: false,
mouseWheelZoom: false
});
readFile(fl);
$(".closeModal").on("click", function () {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (resp) {
$('.upload-msg').css('display', '');
popupResult({
src: resp
});
});
var arr = $uploadCrop.croppie('get').points;
$("#x1").val(arr[0]);
$("#y1").val(arr[1]);
$("#x2").val(arr[2]);
$("#y2").val(arr[3]);
});
我在隐藏的输入字段中获取所有点,然后将这些点传递给 webimge 对象进行裁剪,但问题是裁剪后的图像没有保持纵横比并且裁剪错误,浏览器端裁剪是完美的,但是当我将它传递给服务器端进行裁剪时,它不像浏览器端那样工作,我不知道如何解决这个问题。
【问题讨论】:
-
你做了两次同样的工作......为什么?
-
@Hackerman 我需要在服务器端进行裁剪,但我不知道如何使用croppie 上传服务器端
-
基于这个例子,你只需要上传
result-image:foliotek.com/devblog/…
标签: javascript jquery asp.net asp.net-mvc