Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从mysql数据库中检索视频的缩略图并将其显示在web应用程序上_C#_Asp.net - Fatal编程技术网

C# 如何从mysql数据库中检索视频的缩略图并将其显示在web应用程序上

C# 如何从mysql数据库中检索视频的缩略图并将其显示在web应用程序上,c#,asp.net,C#,Asp.net,请帮忙。。。我被困在这两个星期了。多谢各位 有这些代码吗 public static Bitmap GetThumbnail(string video, string thumbnail) { var cmd = "ffmpeg -itsoffset -1 -i " + '"' + video + '"' + " -vcodec mjpeg -vframes 1 -an -f rawvideo -s 3

请帮忙。。。我被困在这两个星期了。多谢各位

有这些代码吗

public static Bitmap GetThumbnail(string video, string thumbnail)
        {
            var cmd = "ffmpeg  -itsoffset -1  -i " + '"' + video + '"' + " -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 " + '"' + thumbnail + '"';

            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                FileName = "cmd.exe",
                Arguments = "/C " + cmd
            };

            var process = new Process
            {
                StartInfo = startInfo
            };

            process.Start();
            process.WaitForExit(5000);

            return LoadImage(thumbnail);
        }

        static Bitmap LoadImage(string path)
        {
            var ms = new MemoryStream(File.ReadAllBytes(path));
            return (Bitmap)Image.FromStream(ms);    
        }

如何在aspx文件中检索和显示缩略图?

我假设您的代码正在工作并获取位图。。。在本例中,您创建一个处理程序,让它命名为
image.ashx

您将此代码放入处理程序中

public void ProcessRequest(HttpContext context)
{
    // assume its jpeg
    context.Response.ContentType = "image/jpeg";

    // here I call your "working" code
    var cImageToRender = GetThumbnail("VideoName", "thumbnail");

    // convert it for the stream
    var imgData = BitmapToByteArray(cImageToRender);
   
    // send it to the browser
    context.Response.OutputStream.Write(imgData, 0, imgData.Length);    
}

// this function reference
// https://stackoverflow.com/a/17244814/159270
public static byte[] BitmapToByteArray(Bitmap bitmap)
{
    BitmapData bmpdata = null;

    try
    {
        bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
        int numbytes = bmpdata.Stride * bitmap.Height;
        byte[] bytedata = new byte[numbytes];
        IntPtr ptr = bmpdata.Scan0;

        Marshal.Copy(ptr, bytedata, 0, numbytes);

        return bytedata;
    }
    finally
    {
        if (bmpdata != null)
            bitmap.UnlockBits(bmpdata);
    }
}
.aspx
(或任何html)页面中,您可以看到

<img src="image.ashx">

这通常是要遵循的步骤-小细节可能需要在最终代码中修复