Bloom.Book.BookInfo.TryGetPremadeThumbnail C# (CSharp) Method

TryGetPremadeThumbnail() public method

public TryGetPremadeThumbnail ( Image &image ) : bool
image Image
return bool
        public bool TryGetPremadeThumbnail(out Image image)
        {
            string path = Path.Combine(FolderPath, "thumbnail.png");
            if (RobustFile.Exists(path))
            {
                try
                {
                    image = ImageUtils.GetImageFromFile(path);
                    return true;
                }
                catch(Exception e) // If that file became corrupted, we would not want to lock user out of their book.
                {
                    NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All,"Could not read thumbnail.png", "Could not read thumbnail.png at "+FolderPath);
                    //The file will be re-generate now.
                }
            }
            image = null;
            return false;
        }

Usage Example

        private void AddOneBook(BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel, BookCollection collection)
        {
            string title = bookInfo.QuickTitleUserDisplay;
            if (collection.IsFactoryInstalled)
                title = LocalizationManager.GetDynamicString("Bloom", "TemplateBooks.BookName." + title, title);

            var button = new Button
            {
                Size = new Size(ButtonWidth, ButtonHeight),
                Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont,
                TextImageRelation = TextImageRelation.ImageAboveText,
                ImageAlign = ContentAlignment.TopCenter,
                TextAlign = ContentAlignment.BottomCenter,
                FlatStyle = FlatStyle.Flat,
                ForeColor = Palette.TextAgainstDarkBackground,
                UseMnemonic = false, //otherwise, it tries to interpret '&' as a shortcut
                ContextMenuStrip = _bookContextMenu,
                AutoSize = false,

                Tag = new BookButtonInfo(bookInfo, collection, collection == _model.TheOneEditableCollection)
            };

            button.MouseDown += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
            //doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();

            button.Text = ShortenTitleIfNeeded(title, button);
            button.FlatAppearance.BorderSize = 1;
            button.FlatAppearance.BorderColor = BackColor;

            toolTip1.SetToolTip(button, title);

            Image thumbnail = Resources.PagePlaceHolder;
            _bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
            button.ImageIndex = _bookThumbnails.Images.Count - 1;
            flowLayoutPanel.Controls.Add(button); // important to add it before RefreshOneThumbnail; uses parent flow to decide whether primary

            // Can't use this test until after we add button (uses parent info)
            if (!IsUsableBook(button))
                button.ForeColor = Palette.DisabledTextAgainstDarkBackColor;

            Image img;
            var refreshThumbnail = false;
            //review: we could do this at idle time, too:
            if (bookInfo.TryGetPremadeThumbnail(out img))
            {
                RefreshOneThumbnail(bookInfo, img);
            }
            else
            {
                //show this one for now, in the background someone will do the slow work of getting us a better one
                RefreshOneThumbnail(bookInfo,Resources.placeHolderBookThumbnail);
                refreshThumbnail = true;
            }
            _buttonsNeedingSlowUpdate.Enqueue(new ButtonRefreshInfo(button, refreshThumbnail));
        }