Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private void button1_Click(object sender, EventArgs e)
  9.         {
  10.             String foo = File.ReadAllText("c:\\jim.txt").Trim().Replace("\n", "").Replace("\r", "");
  11.  
  12.             Debug.Print(foo.Length.ToString());
  13.  
  14.             Byte[] bar = StringToByteArray(foo);
  15.  
  16.             Debug.Print(bar.Length.ToString());
  17.  
  18.             File.WriteAllBytes("bob.jpg", bar);
  19.  
  20.             pictureBox1.Image = new Bitmap("bob.jpg");
  21.         }
  22.  
  23.         public static byte[] StringToByteArray(string hex)
  24.         {
  25.             return Enumerable.Range(0, hex.Length).
  26.                    Where(x => 0 == x % 2).
  27.                    Select(x => Convert.ToByte(hex.Substring(x, 2), 16)).
  28.                    ToArray();
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement