步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

using SixLabors.ImageSharp.Memory;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace BBWY.Client.Extensions
{
public static class ImageExtensions
{
public static BitmapImage ByteToBitmapImage(this byte[] imageData)
{
BitmapImage bitmapImage = new BitmapImage();
try
{
using (MemoryStream memoryStream = new MemoryStream(imageData))
{
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
bitmapImage.Freeze();
}
return bitmapImage;
}
catch (Exception ex)
{
Debug.Print($"转换图片失败:: {ex.Message}");
}
return bitmapImage;
}
public static Image ByteToImage(this byte[] imageData)
{
using MemoryStream ms = new MemoryStream(imageData);
Image image = System.Drawing.Image.FromStream(ms);
return image;
}
}
}