不裁剪所选区域

裁剪部分现在出现:使用正确的宽度和高度显示图像的不同部分。

要裁剪的区域

在此处输入图像描述

裁剪区 在此处输入图像描述

inheritance人我的js代码

jQuery(document).ready(function () { jQuery('#imgCrop').Jcrop({ onSelect: storeCoords, onChange: storeCoords }); }); function storeCoords(c) { jQuery('#X').val(cx); jQuery('#Y').val(cy); jQuery('#W').val(cw); jQuery('#H').val(ch); }; protected void btnCrop_Click(object sender, EventArgs e) { string ImageName = Session["WorkingImage"].ToString(); 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); pnlCrop.Visible = false; pnlCropped.Visible = true; imgCropped.ImageUrl = "images/crop" + ImageName; } } } 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); } } 

}

我有一个类似的问题,我现在不记得了,但我认为你必须在boxWidth中设置boxWidth选项,特别是如果你没有显示图像的原始大小(图像实际上是1024×768,但你将你的裁剪器设置为350×350 )

此外,您可能必须为jCrop设置aspectRatio ,即使它是01因为它需要根据图像大小重新计算尺寸。 还要确保使用最新版本的0.9.9(截至本文)并检查JavaScript内部是否实际为0.9.9,因为有时他没有正确更新链接..它让我感到…

我认为您的服务器代码是正常的 – 但您需要检查隐藏字段中设置的数字是什么,以便您可以调试问题。