使用asp.net将高分辨率画布图像保存到服务器 [英] Save high resolution canvas image to server using asp.net
本文介绍了使用asp.net将高分辨率画布图像保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码将画布图像保存到Web服务器。但是当图像具有超过200 * 200像素和高分辨率时,它不工作:它不保存。小图像工作;但是具有高分辨率的较大图像不起作用。
I have this code to save a canvas image to the web server. But it is not working when the image has more than 200*200 pixels and high resolution: it does not save. A small image works; but a larger image with high resolution does not work.
<script type="text/Javascript">
function drawShapes() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var imageObj = new Image();
imageObj.src = "im.jpg";
imageObj.onload = function () {
context.drawImage(imageObj, 0, 0, 1800, 1080);
}
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#TZ").click(function () {
var image = document.getElementById("myCanvas").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: 'Include/CS.aspx/UploadImage',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
/*success: function (msg) {
alert('Image saved successfully !');
}*/
});
});
});
</script>
<body onload="drawShapes()">
<form id="form1" runat="server">
<div>
<canvas id="myCanvas" width="1800" height="1080"></canvas>
<a id="TZ">Save</a>
</div>
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.Script.Services;
using System.Web.Services;
[ScriptService]
public partial class Include_CS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod()]
public static void UploadImage(string imageData)
{
string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/");
string fileNameWitPath = path + DateTime.Now.ToString().Replace("/", "-").Replace(" ", "- ").Replace(":", "") + ".png";
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
}
}
推荐答案
您可能需要在web.config中设置maxRequestLength:
You probably need to set the maxRequestLength, something like this in the web.config:
<system.web>
<httpRuntime maxRequestLength="153600" executionTimeout="900" />
</system.web>
请参阅: https://msdn.microsoft.com/en-us/library/e1f13641(v = vs.100).aspx
这篇关于使用asp.net将高分辨率画布图像保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文