private void CreateThumbsDB() { try { RemoveThumbnails(); Application.DoEvents(); this.Invalidate(); File.Delete(this.sourceDirectory + Path.DirectorySeparatorChar + "Thumbs.iw"); FileStream f = File.Open(this.sourceDirectory + Path.DirectorySeparatorChar + "Thumbs.iw", FileMode.OpenOrCreate, FileAccess.Write); string[] tfiles = null; files.Clear(); string[] exts = null; if (thumbnailFileType == ThumbnailFileType.CommonImages) { exts = standardExts; } else if (thumbnailFileType == ThumbnailFileType.DICOM) { exts = dicomExts; } else if (thumbnailFileType == ThumbnailFileType.AllImages) { exts = allExts; } foreach (string ext in exts) { tfiles = Directory.GetFiles(this.sourceDirectory, ext); foreach (string file in tfiles) { files.Add(file); } } files.Sort(); this.Invoke(new ShowProgressCallback(this.ShowProgress), new object[] { files.Count, 0, "Creating/Updating thumbnails" }); int count = 0; Genetibase.NuGenMediImage.Handlers.DicomReader dcm = null; foreach (string file in files) { Bitmap b = null; try { string ext = Path.GetExtension(file).ToUpper(); if (ext == ".DIC" || ext == ".DCM" || ext == ".DICOM") { dcm = new Genetibase.NuGenMediImage.Handlers.DicomReader(file,true); b = (Bitmap)dcm.Images[0]; toolTips.Add(dcm.CompactHeader); } else { b = new Bitmap(file); toolTips.Add(file); } } catch (Exception) { b = (Bitmap)picBoxClone.ErrorImage.Clone(); toolTips.Add(file); } Image thumb = b.GetThumbnailImage(50, 50, null, IntPtr.Zero); MemoryStream ms = new MemoryStream(); thumb.Save(ms, ImageFormat.Bmp); byte[] image = ms.ToArray(); f.Write(image, 0, image.Length); string file1024 = file + new String(' ', 1024 - file.Length); byte[] file1024b = System.Text.ASCIIEncoding.ASCII.GetBytes(file1024); f.Write(file1024b, 0, file1024b.Length); string toolTip1024 = (string)toolTips[count] + new String(' ', 1024 - ((string)toolTips[count]).Length); byte[] toolTip1024b = System.Text.ASCIIEncoding.ASCII.GetBytes(toolTip1024); f.Write(toolTip1024b, 0, toolTip1024b.Length); ms.Dispose(); image = null; file1024b = null; thumb.Dispose(); b.Dispose(); count++; this.Invoke(new ShowProgressCallback(this.ShowProgress),new object[] { files.Count, count, "Creating/Updating thumbnails" }); Application.DoEvents(); } f.Close(); toolTips.Clear(); } catch (Exception) { } finally { this.Invoke(new SimpleDelegate(this.HideProgress)); } }
private void CreateThumbsDB() { try { RemoveThumbnails(); Application.DoEvents(); this.Invalidate(); File.Delete(this.sourceDirectory + Path.DirectorySeparatorChar + "Thumbs.iw"); FileStream f = File.Open(this.sourceDirectory + Path.DirectorySeparatorChar + "Thumbs.iw", FileMode.OpenOrCreate, FileAccess.Write); string[] tfiles = null; files.Clear(); string[] exts = null; if (thumbnailFileType == ThumbnailFileType.CommonImages) { exts = standardExts; } else if (thumbnailFileType == ThumbnailFileType.DICOM) { exts = dicomExts; } else if (thumbnailFileType == ThumbnailFileType.AllImages) { exts = allExts; } foreach (string ext in exts) { tfiles = Directory.GetFiles(this.sourceDirectory, ext); foreach (string file in tfiles) { files.Add(file); } } files.Sort(); this.Invoke(new ShowProgressCallback(this.ShowProgress), new object[] { files.Count, 0, "Creating/Updating thumbnails" }); int count = 0; Genetibase.NuGenMediImage.Handlers.DicomReader dcm = null; foreach (string file in files) { Bitmap b = null; try { string ext = Path.GetExtension(file).ToUpper(); if (ext == ".DIC" || ext == ".DCM" || ext == ".DICOM") { dcm = new Genetibase.NuGenMediImage.Handlers.DicomReader(file, true); b = (Bitmap)dcm.Images[0]; toolTips.Add(dcm.CompactHeader); } else { b = new Bitmap(file); toolTips.Add(file); } } catch (Exception) { b = (Bitmap)picBoxClone.ErrorImage.Clone(); toolTips.Add(file); } Image thumb = b.GetThumbnailImage(50, 50, null, IntPtr.Zero); MemoryStream ms = new MemoryStream(); thumb.Save(ms, ImageFormat.Bmp); byte[] image = ms.ToArray(); f.Write(image, 0, image.Length); string file1024 = file + new String(' ', 1024 - file.Length); byte[] file1024b = System.Text.ASCIIEncoding.ASCII.GetBytes(file1024); f.Write(file1024b, 0, file1024b.Length); string toolTip1024 = (string)toolTips[count] + new String(' ', 1024 - ((string)toolTips[count]).Length); byte[] toolTip1024b = System.Text.ASCIIEncoding.ASCII.GetBytes(toolTip1024); f.Write(toolTip1024b, 0, toolTip1024b.Length); ms.Dispose(); image = null; file1024b = null; thumb.Dispose(); b.Dispose(); count++; this.Invoke(new ShowProgressCallback(this.ShowProgress), new object[] { files.Count, count, "Creating/Updating thumbnails" }); Application.DoEvents(); } f.Close(); toolTips.Clear(); } catch (Exception) { } finally { this.Invoke(new SimpleDelegate(this.HideProgress)); } }