/// <summary> /// Selects clicked image and charge it into new image Viewer /// </summary> private void listView1_DoubleClick(object sender, EventArgs e) { Viewer viewer = new Viewer(this); viewer.Photo = SQLRequests.selectOneImage(tvFolders.SelectedNode.Text, lvImages.SelectedItems[0].Text); viewer.PhotoList = SQLRequests.selectImagesFromFolder(tvFolders.SelectedNode.Text, Int32.Parse(tvFolders.SelectedNode.Parent.Text)); viewer.initializePictureBoxImage(); viewer.Show(); viewer.Focus(); }
/// <summary> /// Displays all images in ListView from TreeView selected folder /// </summary> public void displayImages() { imageList.Images.Clear(); lvImages.Clear(); List <Photos> files = new List <Photos>(); files = SQLRequests.selectImagesFromFolder(tvFolders.SelectedNode.Text, Int32.Parse(tvFolders.SelectedNode.Parent.Text)); orderPhotoList(files); Size s = new Size(100, 75); byte[] bytes = { }; MemoryStream ms; for (int indPhoto = 0; indPhoto < files.Count; indPhoto++) { string path = @".\Cache\" + tvFolders.SelectedNode.Parent.Text + @"\" + tvFolders.SelectedNode.Text + @"\"; if (String.IsNullOrEmpty(files[indPhoto].Alias)) { if (File.Exists(files[indPhoto].FullPath)) { FileInfo fileInfo = new FileInfo(files[indPhoto].FullPath); Bitmap img = new Bitmap(files[indPhoto].FullPath); double ratioWH = img.Size.Width / (double)img.Size.Height; Bitmap png = new Bitmap(100, 75); if (ratioWH >= 1) { img = new Bitmap(img, 100, (int)(100 / ratioWH)); using (Graphics G = Graphics.FromImage(png)) G.DrawImage(img, 0, png.Height / 2 - img.Height / 2); } else { img = new Bitmap(img, (int)(75 * ratioWH), 75); using (Graphics G = Graphics.FromImage(png)) G.DrawImage(img, png.Width / 2 - img.Width / 2, 0); } Icon ic = Icon.FromHandle(png.GetHicon()); imageList.Images.Add(ic); lvImages.Items.Add(fileInfo.Name, indPhoto); if (bgw1.IsBusy) { bgw1.ReportProgress(100 * (indPhoto + 1) / files.Count); } path += files[indPhoto].Name; int resultUpdate = SQLRequests.updatePhotoAlias(path, files[indPhoto].FullPath); if (resultUpdate >= 0) { img.Save(path); } } else { SQLRequests.deletePhoto(files[indPhoto].FullPath); } } else { path += files[indPhoto].Name; FileInfo fileInfo = new FileInfo(path); bytes = File.ReadAllBytes(path); ms = new MemoryStream(bytes); Bitmap img = new Bitmap(Image.FromStream(ms)); double ratioWH = img.Size.Width / (double)img.Size.Height; Bitmap png = new Bitmap(100, 75); if (ratioWH >= 1) { img = new Bitmap(img, 100, (int)(100 / ratioWH)); using (Graphics G = Graphics.FromImage(png)) G.DrawImage(img, 0, png.Height / 2 - img.Height / 2); } else { img = new Bitmap(img, (int)(75 * ratioWH), 75); using (Graphics G = Graphics.FromImage(png)) G.DrawImage(img, png.Width / 2 - img.Width / 2, 0); } Icon ic = Icon.FromHandle(png.GetHicon()); imageList.Images.Add(ic); lvImages.Items.Add(fileInfo.Name, indPhoto); if (bgw1.IsBusy) { bgw1.ReportProgress(100 * (indPhoto + 1) / files.Count); } } } }