private static void CreateImageThumbnail(File file) { using Image image = Image.FromFile(file.GetAbsolutePath()); using Image thumb = image.GetThumbnailImage(240, (int)(240.0 / image.Width * image.Height), () => false, IntPtr.Zero); string guid = Guid.NewGuid().ToString(); thumb.Save(GetThumbnailPath(file), encoder, encParams); }
public static bool TryGenerateExplorerIcon(File file) { string path = file.GetAbsolutePath(); if (!F.Exists(path)) { return(false); } try { string ext = P.GetExtension(path).Replace(".", string.Empty); if (file.IsFolder) { //string guid = GetGuidFromString("folder").ToString(); ////文件夹,统一图标 //if (!F.Exists(GetExplorerIconPath(guid))) //{ // var iconPath = GetExplorerIconPath(guid); // ExplorerIcon.GetBitmapFromFolderPath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon).Save(iconPath, ImageFormat.Png); //} //file.IconGUID = guid; } else if (FileUtility.IsExecutable(path)) { //程序文件,每个图标都不同 string guid = Guid.NewGuid().ToString(); var iconPath = GetExplorerIconPath(file); ExplorerIcon.GetBitmapFromFilePath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon) .Save(iconPath, ImageFormat.Png); } else { var iconPath = GetExplorerIconPath(file); //其他文件,同一个格式的用同一个图标 if (F.Exists(iconPath)) { } else { string tempPath = P.GetTempFileName(); ExplorerIcon.GetBitmapFromFilePath(path, ExplorerIcon.IconSizeEnum.ExtraLargeIcon).Save(tempPath, ImageFormat.Png); try { F.Move(tempPath, iconPath); } catch { } }; } } catch (Exception ex) { } return(false); }
private static async Task CreateWin10ThumbnailAsync(File file) { var sFile = await StorageFile.GetFileFromPathAsync(file.GetAbsolutePath()); using StorageItemThumbnail thumb = await sFile.GetThumbnailAsync(ThumbnailMode.SingleItem); using var bitmap = Bitmap.FromStream(thumb.AsStream()) as Bitmap; Color leftTopColor = bitmap.GetPixel(0, 0); if (leftTopColor.A == byte.MaxValue)//非透明色 { bitmap.Save(GetWin10IconPath(file), encoder, encParams); } else//有透明色 { bitmap.Save(GetWin10IconPath(file), ImageFormat.Png); } }
public static bool TryGenerateWin10Icon(File file) { string path = file.GetAbsolutePath(); if (!F.Exists(path) && !D.Exists(path)) { return(false); } try { CreateWin10ThumbnailAsync(file).Wait(); return(true); } catch (Exception ex) { return(false); } }
public static bool HasIconInCurrentSettings(this File file) { if (Configs.ThumbnailStrategy == ThumbnailStrategy.Win10Icon) { return(file.HasWin10Icon()); } if (Configs.ThumbnailStrategy == ThumbnailStrategy.MediaThumbnailPrefer) { if (file.FileInfo.IsImage() || file.FileInfo.IsVideo()) { return(file.HasThumbnail()); } return(file.HasExplorerIcon()); } if (Configs.ThumbnailStrategy == ThumbnailStrategy.WindowsExplorerIcon) { return(file.HasExplorerIcon()); } return(true); }
private static bool CreateVideoThumbnail(File file) { var thumbnail = GetThumbnailPath(file); var cmd = " -itsoffset -1 -i " + '"' + file.GetAbsolutePath() + '"' + " -vcodec mjpeg -vframes 1 -an -f rawvideo -vf scale=480:-1 " + '"' + thumbnail + '"'; var startInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = P.GetFullPath(FFMpegPath), Arguments = cmd, UseShellExecute = false, CreateNoWindow = true, //RedirectStandardOutput = true, //RedirectStandardError = true, }; Process p = Process.Start(startInfo); bool result = p.WaitForExit(20000); if (!result) { p.Kill(); try { F.Delete(thumbnail); } catch { } return(false); } //string output = p.StandardOutput.ReadToEnd(); //string error = p.StandardError.ReadToEnd(); if (!F.Exists(thumbnail)) { return(false); } return(true); }
public static bool TryGenerateThumbnail(File file) { if (file.IsFolder) { return(false); } string path = file.GetAbsolutePath(); if (!F.Exists(path)) { return(false); } if (FileUtility.IsImage(path)) { try { CreateImageThumbnail(file); return(true); } catch (Exception ex) { return(false); } } else if (FileUtility.IsVideo(path)) { try { return(CreateVideoThumbnail(file)); } catch (Exception ex) { return(false); } } return(false); }
public static bool HasExplorerIcon(this File file) { return(F.Exists(file.GetExplorerIconPath())); }
public static bool HasWin10Icon(this File file) { return(F.Exists(file.GetWin10IconPath())); }
public static bool HasThumbnail(this File file) { return(F.Exists(file.GetThumbnailPath())); }
public static void TryGenerateAllFileIcons(File file) { TryGenerateExplorerIcon(file); TryGenerateWin10Icon(file); TryGenerateThumbnail(file); }
public static string GetExplorerIconPath(this File file) { return(P.GetFullPath(P.Combine(ThumbnailFolderPath, "exp", file.FileInfo.Extension.Trim('.').ToLower() + ".png"))); }
public static string GetWin10IconPath(this File file) { return(P.GetFullPath(P.Combine(ThumbnailFolderPath, "win10", file.ID + ".jpg"))); }
public static string GetThumbnailPath(this File file) { return(P.GetFullPath(P.Combine(ThumbnailFolderPath, "media", file.ID + ".jpg"))); }