我在我的 MVC 应用程序中使用 AsfMojo(在处理程序中)从 WMV 文件中提取 bmp,它在我的本地主机 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 响应。有没有办法在生成图像之前检查文件是否已完全读取。
我会很感激你的建议,在此先感谢。