2012-04-19 62 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