我正在尝试使用 Jcrop 裁剪图像。它不起作用,我不断收到异常“输入字符串的格式不正确”。
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#crop').Jcrop({
onSelect: updateCoords
});
});
function updateCoords(c) {
jQuery('#X').val(c.x);
jQuery('#Y').val(c.y);
jQuery('#W').val(c.w);
jQuery('#H').val(c.h);
};
<asp:Button ID="Submit" runat="server" Text="Crop"
onclick="Submit_Click" />
<asp:Image ID="Image" runat="server" Visible="False" />
<img src="Content/UploadedImage/Image.jpg" id="crop" alt=""/>
<asp:HiddenField ID="X" runat="server" />
<asp:HiddenField ID="Y" runat="server" />
<asp:HiddenField ID="W" runat="server" />
<asp:HiddenField ID="H" runat="server" />
尝试获取坐标
protected void Submit_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
int x = Convert.ToInt32(X.Value);
int y = Convert.ToInt32(Y.Value);
int w = Convert.ToInt32(W.Value);
int h = Convert.ToInt32(H.Value);
最佳答案
这个代码就是我使用的
在客户端我有这个..但我不认为这会造成问题
var updateCoords = function(c) {
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
在服务器“upload.ashx”通用处理程序上,我使用以下方法获取尺寸
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim x As Integer = Integer.Parse(context.Request("x"))
Dim y As Integer = Integer.Parse(context.Request("y"))
Dim w As Integer = Integer.Parse(context.Request("w"))
Dim h As Integer = Integer.Parse(context.Request("h"))
此外,您从哪里得到错误?在客户端还是在服务器上?什么是抛出它?
看起来您正在尝试在回发后获取表单值,这些值不再存在,因为此时页面已重新初始化而没有原始值..因为这就是 .NET 页面渲染过程的工作原理。
因此,您要么必须将变量保存到内存中的 Session,将值回发给自身并使用 Request.Form 检索它们,要么使用 GET 方法发送数据并像我一样检索值
关于asp.net - Jcrop 裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10231456/