Jcrop を Asp.net で動作させようとしていますが、次の点に問題があると思います。
Convert.ToInt32(W.Value);
aspx ページで隠しフィールドを使用しています。私は通常の入力フィールドを使用しようとしましたが、すべての値を取得するためのリクエスト フォームを書きましたが、うまくいきました。しかし、隠しフィールドと Convert.ToInt32(W.Value) で動作させることはできません。そのようにしようとすると、値は常にnullのようです。そして、メッセージが表示されます:入力は正しい形式ではありませんでした。
私の背後にあるコードは次のようになります。
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);
}
}