2012-04-19 65 views
2

我想使用Jcrop裁剪图像。它不工作,我不断收到异常“输入字符串格式不正确”。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" /> 

试图让cordinates

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);   
+0

你检查你的HTML字段的ID或传递什么样的价值观在X.Value,Y.Value,...上回发?我想你必须在你的HiddenField控件中包含'ClientIDMode =“Static”'。 – Jan 2012-04-19 15:37:47

回答

1

嗯,这代码是我用

在客户端我有这样的..但我不认为它会造成问题

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页面呈现过程的工作方式。

所以,你要么必须在vairables保存会话内存,回发值本身和使用的Request.Form检索它们或使用GET方法发送的数据和检索值像我有

1

我在同样的问题,并解决它只是使这个:至少

var updateCoords = function(c) { 

    $('#x1').val(Math.round(c.x)); 
    $('#y1').val(Math.round(c.y)); 
    $('#x2').val(Math.round(c.x2)); 
    $('#y2').val(Math.round(c.y2)); 
    $('#w').val(Math.round(c.w)); 
    $('#h').val(Math.round(c.h)); 
}; 
0
jQuery('#X').val(Math.round(c.x)); 
jQuery('#Y').val(Math.round(c.y)); 
jQuery('#W').val(Math.round(c.w)); 
jQuery('#H').val(Math.round(c.h)); 
+0

没有足够的细节。 – 2017-05-29 14:36:44