標準サムネイルをストリーム経由で取得してListViewに表示。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
imageList1.ImageSize = new Size(256, 256); imageList1.ColorDepth = ColorDepth.Depth24Bit; listView1.LargeImageList = imageList1; string path = textBox2.Text; string[] files; files = System.IO.Directory.GetFiles(path,"*.jpg"); for(int i = 0; i < files.Length; i++) { using (System.IO.FileStream fs = System.IO.File.OpenRead(files[i])) { Image img = Image.FromStream(fs,false,false); Image theme = img.GetThumbnailImage(200, 200, delegate { return false; }, IntPtr.Zero); imageList1.Images.Add(theme); listView1.Items.Add(files[i],i); } } |
ffmpegでサムネイルを取得するタイプ。画像にせず標準出力経由。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
//ffmpegから直接画像として保存 string path = ""; string[] files = System.IO.Directory.GetFiles(path, "*.mp4"); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = Application.StartupPath + @"\ffmpeg.exe"; p.StartInfo.Arguments = "-ss 50 -i \"" + files[0] + "\" -vframes 1 -f image2 tmp1.jpg"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.Start(); //一旦Imageオブジェクトにしてから画像として保存 string path = ""; string[] files = System.IO.Directory.GetFiles(path, "*.mp4"); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = Application.StartupPath + @"\ffmpeg.exe"; p.StartInfo.Arguments = "-ss 50 -i \"" + files[0] + "\" -vframes 1 -f image2 pipe:1"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.Start(); Image img = Image.FromStream(p.StandardOutput.BaseStream); img.Save(Application.StartupPath + @"\tmp2.jpg"); |