获取/传递文件类中的名称?

时间:2012-10-15 06:57:12

标签: c#

我有录音功能并创建缩略图功能。 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();
}

可以从这个帖子查看完整的代码:How to Unlock image files and delete it from specific folder?我添加了另一个generateThumbnail的函数。

2 个答案:

答案 0 :(得分:2)

拆分你的代码,它做得太多了。

private string CreateVideoAndThumbNail()
{
  string fileName = GetFileName();
  GenerateVideo(fileName + ".avi";
  GenerateThumbnail(fileName + ".jpg");
}

private string GetFileName()
{

}

private string GetThumbNail(string path)
{

}

private string GetVideo(string path)
{

}

答案 1 :(得分:0)

AFAIK,静态变量似乎足以达到目的。