12345678910111213141516171819202122232425262728293031323334353637 |
- using System.IO;
- using System.Windows.Media.Imaging;
- namespace Hotel_Course_Project
- {
- class SomeMethods
- {
- #region Конвертирование байтового изображения в стандарт
- public static BitmapImage ConvertByteToBitmapImage(byte[] array)
- {
- using (var ms = new System.IO.MemoryStream(array))
- {
- var image = new BitmapImage();
- image.BeginInit();
- image.CacheOption = BitmapCacheOption.OnLoad;
- image.StreamSource = ms;
- image.EndInit();
- return image;
- }
- }
- #endregion
- #region Конвертирование стандарт изображения в массив байта
- public static byte[] ConvertBitmapImageToByte(BitmapSource image)
- {
- using (var stream = new MemoryStream())
- {
- var encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(image));
- encoder.Save(stream);
- return stream.ToArray();
- }
- }
- #endregion
- }
- }
|