0

我试图让 Jcrop 与 Asp.net 一起工作,但我认为我有一个问题:

Convert.ToInt32(W.Value);

我在我的 aspx 页面中使用隐藏字段。我尝试使用常规输入字段,然后编写了一个请求表单来获取所有值,这很有效。但我无法让它与隐藏字段和 Convert.ToInt32(W.Value) 一起使用。当我尝试这种方式时,该值似乎总是为空。我得到消息:输入的格式不正确。

我的背后代码如下所示:

protected void btnCrop_Click(object sender, EventArgs e)
{
    string ImageName = Request.QueryString["upload"];
    String path = "~/Members/TemporaryProfilePhotos/";

    int w = Convert.ToInt32(W.Value);
    int h = Convert.ToInt32(H.Value);
    int x = Convert.ToInt32(X.Value);
    int y = Convert.ToInt32(Y.Value);

    byte[] CropImage = Crop(path + ImageName, w, h, x, y);

    using (MemoryStream ms = new MemoryStream(CropImage, 0, CropImage.Length))
    {
        ms.Write(CropImage, 0, CropImage.Length);
        using (SD.Image CroppedImage = SD.Image.FromStream(ms, true))
        {
            string SaveTo = path + "crop" + ImageName;
            CroppedImage.Save(SaveTo, CroppedImage.RawFormat);
        }
    }
}

static byte[] Crop(string Img, int Width, int Height, int X, int Y)
{
  try {
    using (SD.Image OriginalImage = SD.Image.FromFile(Img)) {
      using (SD.Bitmap bmp = new SD.Bitmap(Width, Height)) {
        bmp.SetResolution(OriginalImage.HorizontalResolution,
          OriginalImage.VerticalResolution);

        using (SD.Graphics Graphic = SD.Graphics.FromImage(bmp)) {
          Graphic.SmoothingMode = SmoothingMode.AntiAlias;
          Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
          Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
          Graphic.DrawImage(OriginalImage,
            new SD.Rectangle(0, 0, Width, Height),
            X, Y, Width, Height, SD.GraphicsUnit.Pixel);
          MemoryStream ms = new MemoryStream();
          bmp.Save(ms, OriginalImage.RawFormat);
          return ms.GetBuffer();
        }
      }
    }
  }

  catch (Exception Ex) {
    throw (Ex);
  }
} 
4

1 回答 1

1

如果您将 设置Visible propertyfalse;通常在页面之后.netcontrol不会在HTML输出中呈现processed

所以你可以尝试使用隐藏字段style="visibility: hidden; display: none;"

于 2012-05-04T10:03:22.530 回答