Ejemplo n.º 1
0
 internal void UpdateThumbnails(List <Image>?th)
 {
     if (th == null)
     {
         return;
     }
     Thumbnail = th;
     ThumbnailUpdated?.Invoke();
 }
Ejemplo n.º 2
0
        private void MakeThumbnail(Database db)
        {
            try
            {
                lock (this)
                {
                    if (_thumbnail != null || _image == null)
                    {
                        return;
                    }
                    var imageRect = new RectangleF(new PointF(0.0f, 0.0f), _image.Size);
                    if (imageRect.Width > HistoryList.ThumbnailWidth)
                    {
                        imageRect = imageRect.ScaleRectWidth(HistoryList.ThumbnailWidth);
                    }
                    if (imageRect.Height > HistoryList.ThumbnailHeight)
                    {
                        imageRect = imageRect.ScaleRectHeight(HistoryList.ThumbnailHeight);
                    }

                    _thumbnail = new CompressedImage(new Bitmap(_image, (int)imageRect.Width, (int)imageRect.Height));
                    ThumbnailUpdated?.Invoke(this, EventArgs.Empty);
                }

                using (var cmd = db.CreateCommand("update img set thumb = @thumb where path = @path"))
                {
                    cmd.Parameters.AddWithValue("@thumb", _thumbnail.Data);
                    cmd.Parameters.AddWithValue("@path", _location);
                    cmd.ExecuteNonQuery();
                }

                using (var cmd = db.CreateCommand("update history set thumb = @thumb where path = @path"))
                {
                    cmd.Parameters.AddWithValue("@thumb", _thumbnail.Data);
                    cmd.Parameters.AddWithValue("@path", _location);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, "Error when creating image thumbnail.");
                _thumbnail = null;
            }
        }