mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace VPet.ModMaker.Models;
|
|
|
|
/// <summary>
|
|
/// 工具
|
|
/// </summary>
|
|
public static class Utils
|
|
{
|
|
/// <summary>
|
|
/// 解码像素宽度
|
|
/// </summary>
|
|
public const int DecodePixelWidth = 250;
|
|
|
|
/// <summary>
|
|
/// 解码像素高度
|
|
/// </summary>
|
|
public const int DecodePixelHeight = 250;
|
|
public static char[] Separator { get; } = new char[] { '_' };
|
|
|
|
public static ModMakerStyles ModMakerStyles { get; } = new ModMakerStyles();
|
|
|
|
//public static BitmapImage LoadImageToStream(string imagePath)
|
|
//{
|
|
// BitmapImage bitmapImage = new();
|
|
// bitmapImage.BeginInit();
|
|
// bitmapImage.DecodePixelWidth = DecodePixelWidth;
|
|
// try
|
|
// {
|
|
// bitmapImage.StreamSource = new StreamReader(imagePath).BaseStream;
|
|
// }
|
|
// finally
|
|
// {
|
|
// bitmapImage.EndInit();
|
|
// }
|
|
// return bitmapImage;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 载入图片至内存流
|
|
/// </summary>
|
|
/// <param name="imagePath"></param>
|
|
/// <returns></returns>
|
|
public static BitmapImage LoadImageToMemoryStream(string imagePath)
|
|
{
|
|
BitmapImage bitmapImage = new();
|
|
bitmapImage.BeginInit();
|
|
try
|
|
{
|
|
var bytes = File.ReadAllBytes(imagePath);
|
|
bitmapImage.StreamSource = new MemoryStream(bytes);
|
|
bitmapImage.DecodePixelWidth = DecodePixelWidth;
|
|
}
|
|
finally
|
|
{
|
|
bitmapImage.EndInit();
|
|
}
|
|
return bitmapImage;
|
|
}
|
|
}
|