多项功能优化
This commit is contained in:
@@ -10,10 +10,15 @@ namespace Sai.Toolkit.Core.Extensions;
|
||||
|
||||
public static class ImageExtensions
|
||||
{
|
||||
/// <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 Stream stream = File.Create(path);
|
||||
using var stream = File.Create(path);
|
||||
var array = new byte[8192];
|
||||
int count;
|
||||
while ((count = manifestResourceStream.Read(array, 0, array.Length)) > 0)
|
||||
@@ -34,7 +39,12 @@ public static class ImageExtensions
|
||||
var bm = WindowsThumbnailProvider.GetThumbnail(filename, width, height, ThumbnailOptions.None);
|
||||
return Imaging.CreateBitmapSourceFromHBitmap(bm.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 位图转图片
|
||||
/// </summary>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static BitmapImage ToBitmapImage(this Bitmap bitmap)
|
||||
{
|
||||
if (bitmap is null)
|
||||
@@ -59,13 +69,18 @@ public static class ImageExtensions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 位图转像素集
|
||||
/// </summary>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static BitmapSource ToBitmapSource(this Bitmap bitmap)
|
||||
{
|
||||
if (bitmap == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
throw new ArgumentNullException(nameof(bitmap));
|
||||
}
|
||||
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user