private void InitPanel(string imgPath) { int panelInfoHeight = 20; panelImage.Size = new Size(Size.Width, Size.Height - panelInfoHeight); panelImage.Location = new Point(0, 0); panelInfo.Size = new Size(Size.Width, panelInfoHeight); panelInfo.Location = new Point(0, Size.Height - panelInfoHeight); pictureBox.Size = panelImage.Size; pictureBox.Location = new Point(0, 0); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; //pictureBox.Image = ImageTool.GetImage(imgPath); pictureBox.Image = ImageTool.GetThumbnailsImage(imgPath, MainConfig.ImageSize); pictureBox.DoubleClick += pictureBox_DoubleClick; label.Size = panelInfo.Size; label.Location = new Point(0, 0); label.Text = Path.GetFileName(imgPath); label.TextAlign = ContentAlignment.MiddleCenter; label.DoubleClick += label_DoubleClick; //panelInfo.BackColor = Color.Green; //panelImage.BackColor = Color.Red; }
private void Delete_click(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; TreeNode node = (TreeNode)item.Tag; ImageTree imageTree = (ImageTree)node.Tag; string path = imageTree.FullPath; treeViewImg.Nodes.Remove(node); ImageTool.DeleteFile(path); }
private void pictureBox_MouseDown(object sender, MouseEventArgs e) { PictureBox pictureBox = (PictureBox)sender; string filePath = pictureBox.Tag.ToString(); if (e.Button == MouseButtons.Right) { ContextMenuStrip = ImageTool.CreateContextMenuStrip(filePath); } }
/// <summary> /// 单一图片视图 /// </summary> /// <param name="path">图片路径</param> /// <param name="panelSize">窗体大小</param> public SingleView(string path, Size panelSize) { InitializeComponent(); Size = panelSize; pictureBox.Image = ImageTool.GetImage(path); pictureBox.Tag = path; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.DoubleClick += pictureBox_DoubleClick; }
public SingleView() { InitializeComponent(); Size = MainConfig.PanelMainSize; pictureBox.Image = ImageTool.GetImage(MainConfig.ShowImagePath); pictureBox.Tag = MainConfig.ShowImagePath; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.DoubleClick += pictureBox_DoubleClick; }
private void pictureBox_Click(object sender, EventArgs e) { PictureBox pictureBox = sender as PictureBox; string filePath = pictureBox.Tag.ToString(); //pictureBoxLarge.Load(selectPicture.ImageLocation); pictureBoxLarge.Image = ImageTool.GetImage(filePath); pictureBoxLarge.Tag = filePath; pictureBoxLarge.DoubleClick += pictureBoxLarge_DoubleClick; //string selectImagePath = Path.GetFullPath(selectPicture.ImageLocation); ShowImageInfo(filePath); }
private void LoadTreeView(string rootPath, TreeNode rootNode) { DirectoryInfo info = new DirectoryInfo(rootPath); DirectoryInfo[] subDirs = info.GetDirectories().OrderByDescending(tmp => tmp.CreationTime).ToArray(); foreach (DirectoryInfo subDir in subDirs) { // 子文件中没有文件&&文件夹 跳出循环 if (subDir.GetDirectories().Length == 0 && ImageTool.GetFilesByDir(subDir).Length == 0) { continue; } ImageTree folder = new ImageTree(subDir.Name, subDir.FullName, NodeType.Folder); TreeNode folderNode = new TreeNode(subDir.Name); folderNode.Tag = folder; folderNode.ImageKey = "folder.png"; folderNode.SelectedImageKey = "folder-select.png"; rootNode.Nodes.Add(folderNode); DirectoryInfo[] subSubDirs = subDir.GetDirectories(); if (subSubDirs.Length != 0) { LoadTreeView(subDir.FullName.ToString(), folderNode); } FileInfo[] subImgs = ImageTool.GetFilesByDir(subDir); if (subImgs.Length != 0) { foreach (FileInfo img in subImgs) { ImageTree image = new ImageTree(img.Name, img.FullName, NodeType.Image); TreeNode imgNode = new TreeNode(img.Name); imgNode.Tag = image; imgNode.ImageKey = "img.png"; imgNode.SelectedImageKey = "img-select.png"; folderNode.Nodes.Add(imgNode); } } } FileInfo[] imgs = ImageTool.GetFilesByDir(info); foreach (FileInfo img in imgs) { ImageTree image = new ImageTree(img.Name, img.FullName, NodeType.Image); TreeNode imgNode = new TreeNode(img.Name); imgNode.Tag = image; imgNode.ImageKey = "img.png"; imgNode.SelectedImageKey = "img-select.png"; rootNode.Nodes.Add(imgNode); } }
private void ShowSmallImages() { string[] pictures = ImageTool.GetAllImagePath(MainConfig.ShowFolderPath); int pictureCount = pictures.Length; int padding = 2; int columnCount = MainConfig.PanelMainSize.Width / MainConfig.ImageSize.Width; int rowCount = (pictureCount % columnCount == 0) ? pictureCount / columnCount : (pictureCount / columnCount) + 1; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { int index = row * columnCount + column; // 图片下标 PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = MainConfig.ImageSize; if (index >= pictureCount) { return; } //pictureBox.Load(pictures[index]); //pictureBox.Image = Image.FromFile(pictures[index]); //FileStream fs = new FileStream(pictures[index], FileMode.Open); //Bitmap bm = new Bitmap(fs); //fs.Dispose(); //pictureBox.Image = bm; //pictureBox.Image = ImageTool.GetImage(pictures[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(pictures[index], MainConfig.ImageSize); pictureBox.Tag = pictures[index]; Point pictureLoction = new Point() { X = pictureBox.Width * column + padding * (column + 1), Y = pictureBox.Height * row + padding * (row + 1) }; pictureBox.Location = pictureLoction; pictureBox.DoubleClick += pictureBox_DoubleClick; pictureBox.MouseDown += pictureBox_MouseDown; panelMain.Controls.Add(pictureBox); } } }
private void ShowSmallImages() { Size imageSize = new Size(16 * 10, 9 * 10); string[] pictures = ImageTool.GetAllImagePath(@"F:\\- Test\\Bing"); int pictureCount = pictures.Length; int padding = 2; int columnCount = panelMain.Width / imageSize.Width; int rowCount = (pictureCount % columnCount == 0) ? pictureCount / columnCount : (pictureCount / columnCount) + 1; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { int index = row * columnCount + column; // 图片下标 PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = imageSize; if (index >= pictureCount) { return; } //pictureBox.Image = ImageTool.LoadImage(pictures[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(pictures[index], imageSize); pictureBox.Tag = pictures[index]; Point pictureLoction = new Point() { X = pictureBox.Width * column + padding * (column + 1), Y = pictureBox.Height * row + padding * (row + 1) }; //MessageBox.Show(pictureBox.Tag.ToString()); pictureBox.Location = pictureLoction; //Thread t = new Thread(new ParameterizedThreadStart(AddControol)); //t.Start(); panelMain.Controls.Add(pictureBox); Refresh(); } } }
private void ShowSmallImages() { string[] pictures = ImageTool.GetAllImagePath(MainConfig.ShowFolderPath); int pictureCount = pictures.Length; int padding = 2; int columnCount = splitContainer1.Panel1.Width / MainConfig.ImageSize.Width; int rowCount = (pictureCount % columnCount == 0) ? pictureCount / columnCount : (pictureCount / columnCount) + 1; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { int index = row * columnCount + column; PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = MainConfig.ImageSize; if (index >= pictureCount) { return; } //pictureBox.Image = Image.FromFile(pictures[pictureIndex]); //pictureBox.Load(pictures[index]); //pictureBox.Image = ImageTool.GetImage(pictures[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(pictures[index], MainConfig.ImageSize); pictureBox.Tag = pictures[index]; Point pictureLoction = new Point() { X = padding * (column + 1) + pictureBox.Width * column, Y = padding * (row + 1) + pictureBox.Height * row }; pictureBox.Location = pictureLoction; pictureBox.Click += pictureBox_Click; pictureBox.DoubleClick += pictureBox_DoubleClick; panelSmallImages.Controls.Add(pictureBox); } } pictureBoxLarge.Load(pictures[0]); ShowImageInfo(Path.GetFullPath(pictures[0])); }
private void CreateListView() { string[] pictures = ImageTool.GetAllImagePath(MainConfig.ShowFolderPath); listView = new System.Windows.Forms.ListView(); listView.Dock = DockStyle.Fill; //listView1.LabelEdit = true; listView.View = View.Details; listView.AllowColumnReorder = true; listView.CheckBoxes = true; listView.FullRowSelect = true; listView.GridLines = true; // Width of -2 indicates auto-size. listView.Columns.Add("序号", -2, HorizontalAlignment.Left); listView.Columns.Add("文件名", 100, HorizontalAlignment.Left); listView.Columns.Add("分辨率", -2, HorizontalAlignment.Center); listView.Columns.Add("大小", -2, HorizontalAlignment.Center); listView.Columns.Add("文件路径", -2, HorizontalAlignment.Left); listView.Items.Clear(); // Create three items and three sets of subitems for each item. for (int i = 0; i < pictures.Length; i++) { ListViewItem item = new ListViewItem((i + 1).ToString()); ImageListInfo imageInfo = GetImageInfo(Path.GetFullPath(pictures[i])); item.SubItems.Add(imageInfo.FileName); item.SubItems.Add(imageInfo.ImageSize.Width.ToString() + " x " + imageInfo.ImageSize.Height.ToString()); item.SubItems.Add(imageInfo.FileSize.ToString()); item.SubItems.Add(imageInfo.FillFullName); listView.Items.Add(item); } listView.ColumnClick += new ColumnClickEventHandler(ListView_ColumnClick); listView.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(listView_ItemSelectionChanged); listView.ItemChecked += new ItemCheckedEventHandler(listView_ItemChecked); panelListView.Controls.Add(listView); // listview根据列名自动调整列宽 //listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); listView.ListViewItemSorter = imageListViewSort; }
private void LoadSmallImages(string path, Size panelSize, Size imageSize) { string[] pictures = ImageTool.GetAllImagePath(path); int pictureCount = pictures.Length; int padding = 2; int columnCount = panelSize.Width / imageSize.Width; int rowCount = (pictureCount % columnCount == 0) ? pictureCount / columnCount : (pictureCount / columnCount) + 1; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { int index = row * columnCount + column; // 图片下标 PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = imageSize; if (index >= pictureCount) { return; } //pictureBox.Image = ImageTool.GetImage(pictures[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(pictures[index], MainConfig.ImageSize); pictureBox.Tag = pictures[index]; Point pictureLoction = new Point() { X = pictureBox.Width * column + padding * (column + 1), Y = pictureBox.Height * row + padding * (row + 1) }; pictureBox.Location = pictureLoction; pictureBox.DoubleClick += pictureBox_DoubleClick; pictureBox.MouseDown += pictureBox_MouseDown; panelMain.Controls.Add(pictureBox); //Refresh(); } } }
// 加载 curFilePath 的 Image 到 pictureBox private void LoadImage() { Image image = Image.FromFile(imgPath); pictureBox.Image = ImageTool.GetImage(imgPath); //pictureBox.Image = image; pictureBox.SizeMode = PictureBoxSizeMode.StretchImage; StartPosition = FormStartPosition.Manual; Size = GetImageSize(image); pictureBox.Size = Size; //Location = GetStartPoston(image.Size); Location = GetStartPoston(pictureBox.Size); image.Dispose(); GetParentFile(); }
private void ShowSmallImages() { string[] pictures = ImageTool.GetAllImagePath(MainConfig.ShowFolderPath); int pictureCount = pictures.Length; int padding = 2; int pictureHeight = panelSmallImage.Height - 17; int pictureWidth = pictureHeight * 16 / 9; for (int index = 0; index < pictureCount; index++) { PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Width = pictureWidth; pictureBox.Height = pictureHeight; //pictureBox.Image = Image.FromFile(pictures[index]); //pictureBox.Image = ImageTool.GetImage(pictures[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(pictures[index], MainConfig.ImageSize); pictureBox.Tag = pictures[index]; //FileStream fs = new FileStream(pictures[cnt], FileMode.Open); //Bitmap bm = new Bitmap(fs); //fs.Dispose(); //pictureBox.Image = bm; Point pictureLoction = new Point() { X = padding * (index + 1) + pictureWidth * index, Y = 0 }; pictureBox.Location = pictureLoction; pictureBox.Click += smallPictureBox_Click; pictureBox.DoubleClick += pictureBox_DoubleClick; panelSmallImage.Controls.Add(pictureBox); } pictureBoxLarge.Image = Image.FromFile(pictures[0]); }
private void CreateSmallImages() { panelSmallImage.Controls.Clear(); Size panelSize = panelSmallImage.Size; List <string> imagePath = new List <string>(); foreach (ListViewItem item in listView.CheckedItems) { string path = listView.Items[item.Index].SubItems[4].Text; imagePath.Add(path); } if (imagePath.Count == 0) { return; } // 遍历删除 control //foreach (Control control in panelSmallImages.Controls) //{ // PictureBox picBox = (PictureBox)control; // string path = Path.GetFullPath(picBox.ImageLocation); // if (imagePath.Contains(path)) // return; // else // panelSmallImages.Controls.Remove(control); //} int columnCount = 3; int rowCount = (imagePath.Count % columnCount == 0) ? imagePath.Count / columnCount : (imagePath.Count / columnCount) + 1; int padding = 2; int pictureWidth = panelSize.Width / columnCount - 2 * padding; int pictureHeight = pictureWidth * 9 / 16; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { int index = row * columnCount + column; // 图片下标 PictureBox pictureBox = new PictureBox(); pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Width = pictureWidth; pictureBox.Height = pictureHeight; if (index >= imagePath.Count) { return; } //FileStream fs = new FileStream(imagePath[index], FileMode.Open); //Bitmap bm = new Bitmap(fs); //fs.Dispose(); //pictureBox.Image = bm; //pictureBox.Image = ImageTool.GetImage(imagePath[index]); pictureBox.Image = ImageTool.GetThumbnailsImage(imagePath[index], MainConfig.ImageSize); pictureBox.Tag = imagePath[index]; //pictureBox.Load(imagePath[pictureIndex]); //pictureBox.Image=Image.FromFile(imagePath[pictureIndex]); Point pictureLoction = new Point(); pictureLoction.X = padding * (column + 1) + pictureWidth * column; pictureLoction.Y = padding * (row + 1) + pictureHeight * row; pictureBox.Location = pictureLoction; pictureBox.DoubleClick += pictureBox_DoubleClick; panelSmallImage.Controls.Add(pictureBox); } } }
public void GetParentFile() { parentFilePath = ImageTool.GetAllImagePath(Path.GetDirectoryName(imgPath)).ToList(); }