Beispiel #1
0
        public Bitmap ThumbnailForFile(string FilePath, ThumbnailSizes thumbSize, ref string txtLog)
        {
            if (
                (!File.Exists(FilePath)) &&
                (!Directory.Exists(FilePath))
                )
            {
                return(null);
            }

            if (ShellFile.IsPlatformSupported)
            {
                try
                {
                    using (ShellFile sf = ShellFile.FromFilePath(FilePath))
                    {
                        if (sf == null)
                        {
                            return(null);
                        }

                        ShellThumbnail thumb = sf.Thumbnail;
                        if (thumb == null)
                        {
                            return(null);
                        }

                        switch (thumbSize)
                        {
                        case ThumbnailSizes.Medium:
                            return(thumb.MediumBitmap);

                        case ThumbnailSizes.Large:
                            return(thumb.LargeBitmap);

                        case ThumbnailSizes.ExtraLarge:
                            return(thumb.ExtraLargeBitmap);

                        default:     //case ThumbnailSizes.Small:
                            return(thumb.SmallBitmap);
                        }
                    }
                }
                catch
                {
                    // Do not return; try legacy method
                }
            }

            // Use legacy method
            LegacyThumbnailExtractor2 tc = new LegacyThumbnailExtractor2(thumbSize);


            Bitmap bThumb = null;
            Bitmap bmpNew = null;

            bThumb = tc.GetThumbnail(FilePath);

            // No thumbnail returned - look for folder.jpg (for MP3s)
            if (bThumb != null)
            {
                bmpNew = (Bitmap)bThumb.Clone();
            }
            else
            {
                // NB: use a new thumbnail extractor
                string stub      = Path.GetDirectoryName(FilePath);
                string artworkFN = Path.Combine(stub, "folder.jpg");

                txtLog += "Artwork FN: " + artworkFN + Environment.NewLine;
                if (File.Exists(artworkFN))
                {
                    bThumb = tc.GetThumbnail(artworkFN);

                    if (bThumb != null)
                    {
                        bmpNew = (Bitmap)bThumb.Clone();
                    }
                }
            }

            return(bmpNew);
        }
Beispiel #2
0
        public Bitmap ThumbnailForFile(string FilePath, ThumbnailSizes thumbSize, ref string txtLog)
        {
            if (
                (!File.Exists(FilePath)) &&
                (!Directory.Exists(FilePath))
                )
                return null;

            if (ShellFile.IsPlatformSupported)
            {
                try
                {
                    using (ShellFile sf = ShellFile.FromFilePath(FilePath))
                    {
                        if (sf == null) return null;

                        ShellThumbnail thumb = sf.Thumbnail;
                        if (thumb == null) return null;

                        switch (thumbSize)
                        {
                            case ThumbnailSizes.Medium:
                                return thumb.MediumBitmap;

                            case ThumbnailSizes.Large:
                                return thumb.LargeBitmap;

                            case ThumbnailSizes.ExtraLarge:
                                return thumb.ExtraLargeBitmap;

                            default: //case ThumbnailSizes.Small:
                                return thumb.SmallBitmap;
                        }

                    }
                }
                catch
                {
                    // Do not return; try legacy method
                }
            }

            // Use legacy method
            LegacyThumbnailExtractor2 tc = new LegacyThumbnailExtractor2(thumbSize);

            Bitmap bThumb = null;
            Bitmap bmpNew = null;

            bThumb = tc.GetThumbnail(FilePath);

            // No thumbnail returned - look for folder.jpg (for MP3s)
            if (bThumb != null)
            {
                bmpNew = (Bitmap)bThumb.Clone();
            }
            else
            {
                // NB: use a new thumbnail extractor
                string stub = Path.GetDirectoryName(FilePath);
                string artworkFN = Path.Combine(stub, "folder.jpg");

                txtLog += "Artwork FN: " + artworkFN + Environment.NewLine;
                if (File.Exists(artworkFN))
                {
                    bThumb = tc.GetThumbnail(artworkFN);

                    if (bThumb != null)
                        bmpNew = (Bitmap)bThumb.Clone();
                }
            }

            return bmpNew;
        }