asp.net - Jcrop 裁剪图像

标签 asp.net crop 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" /> 

尝试获取坐标

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/

相关文章:

c# - 裁剪图像通用应用程序 C#

iphone - 不使用捏合/UIScrollView 缩小照片

javascript - 在 GWT JSNI 中调用 JCrop

angularjs - 使用 AngularJS 裁剪图像

asp.net - 如何在asp.net中的gridview中检索文本框值

javascript - 是否可以通过 Jquery .ajax() 方法使用路径获取 webmethod 中的文件?

javascript - "chkAutoPick.Checked ? string.Empty : "来自 : "+ txtDtFrom.Text" in javascript 的含义是什么

asp.net - 在 asp.net 处理程序中访问 session

Android 位图旋转 Canvas 裁剪/剪切图像

javascript - 保持纵横比