我在我的MVC应用程序中使用AsfMojo(在处理程序中)从WMV文件中提取bmp,它在我的localhost IIS7上工作得很好,但是当我将应用程序发布到我们的托管服务时,图像没有显示。
视图脚本:
<img id="Image1" alt="image" src="ImageHandler.ashx?img=CT0001.wmv" height="512" width="512" />
处理程序脚本:
string videoname = System.Web.HttpContext.Current.Server.MapPath("Video/" + sImageFileName);
if(File.Exists(videoname))
{
Bitmap bmp = AsfImage.FromFile(videoname).AtOffset(timeOffset);
bmp.Save(objMemoryStream, ImageFormat.Png);
byte[] imageContent = new byte[objMemoryStream.Length];
objMemoryStream.Position = 0;
objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length);
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(imageContent);
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(5));
当我尝试使用Chrome在新窗口中显示图片时出现以下错误消息:
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: image]
System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height) +1133063
DirectshowTest.ImageHandler.ProcessRequest(HttpContext context) in E:\..\projects\DirectshowTest\DirectshowTest\ImageHandler.ashx.cs:40
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
我怀疑由于wmv文件的大小,处理程序脚本不会等到它读取此行中文件中的所有帧:
Bitmap bmp = AsfImage.FromFile(videoname).AtOffset(timeOffset);
我试图在没有任何运气的情况下缓存contnet响应。有没有办法在生成图像之前检查文件是否已完全读取。
我很感激你的建议,谢谢你。