Crop transparent edges from icons then center it

This commit is contained in:
Jaex 2019-05-15 01:53:14 +03:00
parent 791f9fb693
commit 2c01aea2bc

View file

@ -159,37 +159,41 @@ public void UpdateThumbnail()
{ {
string filePath = Task.Info.FilePath; string filePath = Task.Info.FilePath;
try if (!string.IsNullOrEmpty(filePath))
{ {
if (Helpers.IsImageFile(filePath)) try
{ {
using (Image img = ImageHelpers.LoadImage(filePath)) if (Helpers.IsImageFile(filePath))
{ {
if (img != null) using (Image img = ImageHelpers.LoadImage(filePath))
{ {
//ThumbnailImage = ImageHelpers.CreateThumbnail(img, ThumbnailSize.Width, ThumbnailSize.Height); if (img != null)
ThumbnailImage = ImageHelpers.ResizeImage(img, ThumbnailSize, false); {
//ThumbnailImage = ImageHelpers.CreateThumbnail(img, ThumbnailSize.Width, ThumbnailSize.Height);
ThumbnailImage = ImageHelpers.ResizeImage(img, ThumbnailSize, false);
pbThumbnail.Image = ThumbnailImage;
ThumbnailSourceFilePath = filePath;
pbThumbnail.Cursor = pThumbnail.Cursor = Cursors.Hand;
}
}
}
else
{
using (Icon icon = NativeMethods.GetJumboFileIcon(filePath))
using (Bitmap bmp = icon.ToBitmap())
using (Image img = ImageHelpers.AutoCropTransparent(bmp))
{
ThumbnailImage = ImageHelpers.ResizeImage(img, ThumbnailSize, false, true);
pbThumbnail.Image = ThumbnailImage; pbThumbnail.Image = ThumbnailImage;
ThumbnailSourceFilePath = filePath; pbThumbnail.Cursor = pThumbnail.Cursor = Cursors.Default;
pbThumbnail.Cursor = pThumbnail.Cursor = Cursors.Hand;
} }
} }
} }
else catch (Exception e)
{ {
using (Icon icon = NativeMethods.GetJumboFileIcon(filePath)) DebugHelper.WriteException(e);
using (Image img = icon.ToBitmap())
{
ThumbnailImage = ImageHelpers.ResizeImage(img, ThumbnailSize, false);
pbThumbnail.Image = ThumbnailImage;
pbThumbnail.Cursor = pThumbnail.Cursor = Cursors.Default;
}
} }
} }
catch (Exception e)
{
DebugHelper.WriteException(e);
}
} }
} }