The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
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.

ByteHelper.cs 812B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. using System.IO;
  8. namespace Teknik.Utilities
  9. {
  10. public static class ByteHelper
  11. {
  12. public static byte[] ImageToByte(Image img)
  13. {
  14. byte[] byteArray = new byte[0];
  15. using (MemoryStream stream = new MemoryStream())
  16. {
  17. img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  18. stream.Close();
  19. byteArray = stream.ToArray();
  20. }
  21. return byteArray;
  22. }
  23. public static void PadToMultipleOf(ref byte[] src, int pad)
  24. {
  25. int len = (src.Length + pad - 1) / pad * pad;
  26. Array.Resize(ref src, len);
  27. }
  28. }
  29. }