网络 MVC4 应用程序。如何在我的 asp.net mvc4 应用程序中生成视频文件。我有一组 URL,它们是 base64 格式的图像序列,从画布输出生成。请建议我控制器代码。
问问题
1176 次
1 回答
1
这是发送画布数据的 ajax 和接收它的控制器代码:
// Send the canvas image to the server using ajax
// You can modify this ajax to fit your needs,
var canvas=getElementById("yourCanvas");
var image = canvas.toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: 'yourController/UploadImage',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg){ console.log(msg); }
});
// receive the 64bit encoded string in the controller
// I just convert it to an Image,
// but you can do what you want with the MemoryStream
[HttpPost]
public ActionResult UploadImage(string imageData)
{
byte[] byteArray = System.Convert.FromBase64String(imageData);
// convert to an image (or do whatever else you need to do)
Image image;
using(MemoryStream s=new MemoryStream(byteArray){
image=Image.FromStream(ms);
}
return("done");
}
于 2013-02-16T17:31:37.653 回答