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;
        }
    }
}