net MVC4应用。 如何在我的asp.net mvc4应用程序中生成视频文件。我有一系列URL,这些URL是base64格式的图像序列,从canvas输出生成。请建议我控制器代码。
答案 0 :(得分: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");
}