Please see my code below.
I want to create a Byte array with data that I can convert into a real image. When I try to run this code I get an argumentException. What do I need to do in the For loop in order to create a legitimate Byte array that will hold data of an image? I don't want to use a real image and convert it to byte array, I want to create an image form random numbers.
Random Rnd = new Random(); public MainWindow() { InitializeComponent(); } private void Button_Click_1(object sender, RoutedEventArgs e) { Byte[] ByteArray = new Byte[1000]; for (int i = 0; i < 1000; i++) { ByteArray[i] = Convert.ToByte(Rnd.Next(9)); } ImageConverter Convertor = new ImageConverter(); BitmapImage image = (BitmapImage)Convertor.ConvertFrom(ByteArray); MyImage.Source = image; }
Notice please that I don't want to work with WinForms types or libraries like system.drawing / bitmap - I only want to use WPF technology.