using CPF.Drawing;
using System.IO;

namespace OVCS.ClientLinux.Tools
{
    internal class BitmapHelper
    {
        public static Image Convert(byte[] bytes)
        {
            Bitmap img = null;
            if (bytes != null && bytes.Length > 0)
            {
                MemoryStream ms = new MemoryStream(bytes);
                img = new Bitmap(ms);
            }
            return img;
        }

        public static byte[] Bitmap2Byte(Image bitmap)
        {
            using (Stream stream = bitmap.SaveToStream(CPF.Drawing.ImageFormat.Png))
            {
                byte[] data = new byte[stream.Length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(data, 0, (int)stream.Length);
                return data;
            }

        }
    }
}
