Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String foo = File.ReadAllText("c:\\jim.txt").Trim().Replace("\n", "").Replace("\r", "");
- Debug.Print(foo.Length.ToString());
- Byte[] bar = StringToByteArray(foo);
- Debug.Print(bar.Length.ToString());
- File.WriteAllBytes("bob.jpg", bar);
- pictureBox1.Image = new Bitmap("bob.jpg");
- }
- public static byte[] StringToByteArray(string hex)
- {
- return Enumerable.Range(0, hex.Length).
- Where(x => 0 == x % 2).
- Select(x => Convert.ToByte(hex.Substring(x, 2), 16)).
- ToArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement