using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Extensometer.WinForm { public class PathGetPmgImageClass { private static List Bitmaps = new List(); //private static List GetFile = new List(); public List GetBitmaps(string Path) { getdir(Path); return Bitmaps; } private static void getdir(string Path) { try { string extName = ".bmp"; string[] dir = Directory.GetDirectories(Path); //文件夹列表 DirectoryInfo fdir = new DirectoryInfo(Path); FileInfo[] file = fdir.GetFiles(); //FileInfo[] file = Directory.GetFiles(path); //文件列表 if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空 { foreach (FileInfo f in file) //显示当前目录所有文件 { if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0) { //GetFile.Add(f); Bitmaps.Add(new Bitmap(Image.FromFile(f.FullName))); } } foreach (string d in dir) { getdir(d);//递归 } } } catch { } } private Bitmap BytesToBitmap(byte[] Bytes) { MemoryStream stream = null; try { stream = new MemoryStream(Bytes); return new System.Drawing.Bitmap((System.Drawing.Image)new System.Drawing.Bitmap(stream)); } catch (ArgumentNullException ex) { throw ex; } catch (ArgumentException ex) { throw ex; } finally { stream.Close(); } } private byte[] BitmapToBytes(Bitmap bitmap) { byte[] _imgData = null; using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Bmp); _imgData = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Read(_imgData, 0, Convert.ToInt32(ms.Length)); } return _imgData; } } }