C# Graphics 绘制视频剧照

最终效果图
// 图片截取:
//  C:\ffmpeg-20160921-7447ec9-win64-static\bin\ffmpeg.exe -i C:\Users\Master\Dropbox\视频\0001.新浪网-樱花-遇到你真好~~.flv -s 250x140 -vf fps=1/30 C:\Users\Master\Dropbox\程序源码\C#\WinForm\DrawImage\DrawImage\bin\Debug\Capture\img1%03d.jpg
var imgList = Directory.GetFiles(@"C:\Users\Master\Dropbox\程序源码\C#\WinForm\DrawImage\DrawImage\bin\Debug\Capture");
var oneImgWidth = 250;
var oneImgHeight = 140;
var headerHeight = 70;
var interval = 4;
var columnCount = 3;
var totalWidth = columnCount * oneImgWidth + (columnCount + 1) * interval;
var rowCount = (imgList.Count() + columnCount - 1) / columnCount;
var totalHeight = rowCount * oneImgHeight + (rowCount + 1) * interval + headerHeight;

var rowNo = 0;
var colNo = 0;
var bmp = new Bitmap(totalWidth, totalHeight);
var g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.White, new Rectangle() { X = 0, Y = 0, Height = totalHeight, Width = totalWidth });
g.DrawString("\n  文件名称: 0001.新浪网-樱花-遇到你真好~~.flv\n  文件大小: 10.6 MB  视频尺寸: 512*288  视频时长: 00:04:55", new Font("楷体",13,FontStyle.Bold), Brushes.Black, new PointF() { X = 0, Y = 0 });

foreach (var file in imgList)
{
    int imgX = colNo * oneImgWidth + (colNo + 1) * interval;
    int imgY = rowNo * oneImgHeight + (rowNo + 1) * interval + headerHeight;

    g.DrawImage(Image.FromFile(file), imgX, imgY);

    colNo++;
    if ((colNo % columnCount) == 0)
    {
        rowNo++;
        colNo = 0;
    }

}
bmp.Save("1.bmp");
return;

原代码为 QT,改了几处变为 C# 版本 (:з」∠),原作者:
http://www.cnblogs.com/haibindev/archive/2011/06/29/2079300.html

2 Replies to “C# Graphics 绘制视频剧照”

    1. 偶尔看看,主题换了几次了,文章一直没更新。忙于工作,没啥东西可以记录(你有一封一年后的邮件,请查收

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据