45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Reflection;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Interop;
|
|||
|
|
using System.Windows.Media.Imaging;
|
|||
|
|
|
|||
|
|
namespace ShrlAlgoToolkit.Core.Assists;
|
|||
|
|
public class ImageAssist
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 提取资源
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="resourceName"></param>
|
|||
|
|
/// <param name="path"></param>
|
|||
|
|
public static void ExtractResource(string resourceName, string path)
|
|||
|
|
{
|
|||
|
|
using var manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
|
|||
|
|
using var stream = File.Create(path);
|
|||
|
|
var array = new byte[8192];
|
|||
|
|
int count;
|
|||
|
|
while ((count = manifestResourceStream.Read(array, 0, array.Length)) > 0)
|
|||
|
|
{
|
|||
|
|
stream.Write(array, 0, count);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 资源管理器缩略图读取
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="filename"></param>
|
|||
|
|
/// <param name="width"></param>
|
|||
|
|
/// <param name="height"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static BitmapSource LoadFileImage(string filename, int width, int height)
|
|||
|
|
{
|
|||
|
|
var bm = WindowsThumbnailProvider.GetThumbnail(filename, width, height, ThumbnailOptions.None);
|
|||
|
|
return Imaging.CreateBitmapSourceFromHBitmap(bm.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
|||
|
|
}
|
|||
|
|
}
|