我有录音功能和创建缩略图功能。doRecording()
类创建一个名称为 dateTime 格式的 avi 文件。然后,我有另一个类,generateThumbnail()
我想做的是将缩略图名称与doRecording()
函数中的视频文件名相同。
private void doRecording()
{
string ImagePath = Server.MapPath("~\\Videos\\liveRecording2\\");
string SavingPath = Server.MapPath("~\\Videos\\liveRecording2\\"); //recorded video path
string VideoName = "ICS-" + String.Format("{0:yyyyMMdd_hhmmss}", DateTime.Now) + ".avi";
writer.Open(SavingPath + VideoName, 640, 480); //create an AVI file and open it for images adding
// create frame image
Bitmap image = new Bitmap(320, 240);
string[] files = Directory.GetFiles(ImagePath);
writer.FrameRate = 25;
int index = 0;
int failed = 0;
foreach (var item in files)
{
index++;
try
{
image = Image.FromFile(item) as Bitmap;
//image = cubit.Apply(image);
for (int i = 0; i < 5; i++)
{
writer.AddFrame(image);
}
}
catch
{
failed++;
}
//this.Text = index + " of " + files.Length + ". Failed: " + failed;
}
writer.Close();
writer.Dispose();
this.Label1.Text = "status: Video was successfully created";
DeleteImage();
}
private void generateThumbnail()
{
string fileName = "5.jpg";
string ThumbFolderPath = "~\\Videos\\liveRecording2\\";
string OriginalFolderPath = "~\\Videos\\liveRecording2\\";
//Get The Image From File
System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(OriginalFolderPath + fileName));
//Create ITs Thumbnail
System.Drawing.Image ThumbImage = OriginalImage.GetThumbnailImage(60, 30, null, new System.IntPtr());
//Store It in Thumbnail Folder
ThumbImage.Save(HttpContext.Current.Server.MapPath(ThumbFolderPath + "thumb_" + thumbName + ".jpeg"));
OriginalImage.Dispose();
}
完整的代码可以从这个线程中查看:如何解锁图像文件并将其从特定文件夹中删除?
我添加了另一个功能,即generateThumbnail
.