/// <summary> /// Метод восстановления изображения из набора байтов /// </summary> /// <param name="input">Набор байтов, представляющий изображение</param> /// <param name="width">Ширина изображения</param> /// <param name="height">высота изображения</param> /// <returns>Возвращает Bitmap</returns> public static Bitmap GetBitmap(byte[] input, int width, int height) { if (input.Length%4 != 0) throw new ArgumentException(string.Format("ERROR! BitmapData is corrupted!")); var output = new Bitmap(width, height); var run = new BitmapUnsafeMethods(output); run.LockImageWithoutAlpha(); Marshal.Copy(input, 0, run.ReturnBitmapDataPointer(), input.Length); run.UnlockImage(); return output; }
/// <summary> /// Метод для получения массива байтов с изображения /// </summary> /// <param name="input">Изображение для получения набора байтов</param> /// <returns> /// набор байтов с изображения /// </returns> public static byte[] GetBytes(Bitmap input) { int bytesCount = input.Width*input.Height*4; var run = new BitmapUnsafeMethods(input); run.LockImageWithoutAlpha(); byte[] output = run.ReturnBytesFromLockImage(bytesCount); run.UnlockImage(); return output; }