我有两个上传和保存图像的步骤,在第一步中,上传图像并向用户显示预览以进行裁剪,在第二步中使用JQuery插件用户选择预期区域并单击裁剪图像按钮。 / p>
在下面你可以看到CropImage()
动作。
[HttpPost]
public async Task<ActionResult> CropImage(UploadImage data)
{
string fileName = data.fileName;
string path;
path = Path.Combine(Server.MapPath("~/Images/UsersImages/"), fileName);
data.url = "https://example.com/Images/UsersImages/" + fileName + "?crop=" + data.x1 +
"," + data.y1 + "," + data.x2 + "," + data.y2 + "&&width=309&&height=411&mode=max";
Bitmap img = new Bitmap(data.GetStreamFromUrl());
img.Save(path);
}
这里是UploadImage
课程:
public class UploadImage
{
public string url { get; set; }
public string fileName { get; set; }
public string x1 { get; set; }
...
public Stream GetStreamFromUrl()
{
byte[] imageData;
using (var wc = new System.Net.WebClient())
imageData = wc.DownloadData(url);
return new MemoryStream(imageData);
}
}
如果我想保存裁剪的图像,我会收到以下错误:
GDI +中发生了一般错误
InnerException:at System.Drawing.Image.Save(String filename,ImageCodecInfo encoder,EncoderParameters encoderParams)
我启用了在服务器上写入的所有权限。
如何保存裁剪的图像?