Example #1
0
    /// <summary>
    /// Create a "file print" for a multi-media file. First this detects the file type (image or video) and then creates a small thumbnail for it and caches it in
    /// SorterExpress's thumbnail store.
    /// </summary>
    /// <exception cref="Exception">Can throw any manner of exceptions because of constantly manipulating files.</exception>
    public FilePrint(string filePath)
    {
        this.Filepath = filePath;
        Bitmap thumbImage;

        Directory = Path.GetDirectoryName(filePath);
        FileType  = Utilities.GetFileType(Filepath);

        ThumbPath = Path.Combine(Program.THUMBS_PATH, Utilities.MD5(filePath) + ".jpg");

        if (File.Exists(ThumbPath))
        {
            thumbImage = new Bitmap(ThumbPath);
        }
        else
        {
            if (FileType == FileType.Image)
            {
                var fullImage = new Bitmap(filePath);
                size       = fullImage.Size;
                thumbImage = Utilities.Resize(fullImage, THUMB_SIZE, THUMB_SIZE);
                thumbImage.Save(ThumbPath);

                fullImage.Dispose();
            }
            else if (FileType == FileType.Video)
            {
                FFWorker.GetThumbnailWait(filePath, ThumbPath, THUMB_SIZE);

                // Should put a try catch around this, if file is corrupted or anything it leads to issues.
                thumbImage = new Bitmap(ThumbPath);
            }
            else
            {
                throw new InvalidOperationException("Creating FilePrint, file must be an Image or Video.");
            }
        }

        if (thumbImage == null)
        {
            throw new Exception("ThumbImage should have been loaded by this point in order to calculate image print");
        }

        CalculateImagePrint(thumbImage);

        thumbImage.Dispose();
    }
Example #2
0
    private Size GetSize()
    {
        if (FileType == FileType.Image)
        {
            using (var imageStream = File.OpenRead(Filepath))
            {
                var decoder = BitmapDecoder.Create(imageStream, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                var width   = decoder.Frames[0].PixelWidth;
                var height  = decoder.Frames[0].PixelHeight;
                return(new Size(width, height));
            }
        }
        else if (FileType == FileType.Video)
        {
            return(FFWorker.GetSizeWait(Filepath));
        }

        return(new Size(-1, -1));
    }
Example #3
0
        private Button CreateFileButton(string filename)
        {
            Button button = new Button();

            button.Size = new Size(65, 65);

            if (Utilities.videoFileExtensions.Contains(Path.GetExtension(filename)))
            {
                string thumbnailFilename = Program.THUMBS_PATH + "\\" + Utilities.MD5(filename) + ".jpg";

                if (!File.Exists(thumbnailFilename))
                {
                    FFWorker.GetThumbnailAsync(directory + "\\" + filename, thumbnailFilename, 60, (s) =>
                    {
                        try
                        {
                            button.Image = Image.FromFile(s);
                        }
                        catch
                        {
                            button.Image = null;
                            button.Text  = s;
                        }
                    });
                }
                else
                {
                    button.Image = Image.FromFile(thumbnailFilename);
                }
            }
            else
            {
                button.Image = Image.FromFile(directory + "/" + filename).GetThumbnailImage(50, 50, null, IntPtr.Zero);
            }

            button.Name = filename;
            tooltip.SetToolTip(button, filename);

            button.Click += fileButton_Click;

            return(button);
        }