public void GenerateThumbnail() { if (ArtFullPath.Trim().Length == 0) { return; } string thumbsFolder = null; if (this.GetType() == typeof(DBTrackInfo)) { thumbsFolder = mvCentralCore.Settings.TrackArtThumbsFolder; } if (this.GetType() == typeof(DBAlbumInfo)) { thumbsFolder = mvCentralCore.Settings.AlbumArtThumbsFolder; } if (this.GetType() == typeof(DBArtistInfo)) { thumbsFolder = mvCentralCore.Settings.ArtistArtThumbsFolder; } string filename = new FileInfo(ArtFullPath).Name; string fullname = thumbsFolder + '\\' + filename; if (File.Exists(fullname)) { _thumbfullpath = fullname; return; } Image track = null; try { track = Image.FromFile(ArtFullPath); } catch (OutOfMemoryException e) { logger.DebugException("Invalid image or image format not supported.", e); return; } catch (FileNotFoundException e) { logger.DebugException("File not found.", e); return; } if (track == null) { logger.Error("Error while trying to create thumbnail."); return; } int width = 175; int height = (int)(track.Height * ((float)width / (float)track.Width)); Image trackThumb = track.GetThumbnailImage(width, height, null, IntPtr.Zero); if (saveImage(fullname, trackThumb)) { _thumbfullpath = fullname; commitNeeded = true; } track.Dispose(); trackThumb.Dispose(); }
// removes the current trackimage from the selection list and deletes it and it's thumbnail // from disk public void DeleteCurrentArt() { string FilePath = ArtFullPath; string ThumbFilePath = ArtThumbFullPath; // delete thumbnail if (ThumbFilePath.Trim().Length > 0) { FileInfo thumbFile = new FileInfo(ThumbFilePath); if (thumbFile.Exists) { try { thumbFile.Delete(); } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) { throw e; } } } } // If using a custom artwork folder then dont delete the artwork.... if ((ArtFullPath.Contains(mvCentralCore.Settings.CustomArtistArtFolder) && mvCentralCore.Settings.SearchCustomFolderForArtistArt) || (ArtFullPath.Contains(mvCentralCore.Settings.CustomAlbumArtFolder) && mvCentralCore.Settings.SearchCustomFolderForAlbumArt) || (ArtFullPath.Contains(mvCentralCore.Settings.CustomTrackArtFolder) && mvCentralCore.Settings.SearchCustomFolderForTrackArt)) { ArtFullPath = ""; AlternateArts.Remove(FilePath); commitNeeded = true; return; } // delete trackimage if (FilePath.Trim().Length > 0) { FileInfo File = new FileInfo(FilePath); if (File.Exists) { try { File.Delete(); } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) { throw e; } } } } ArtFullPath = ""; AlternateArts.Remove(FilePath); commitNeeded = true; }