c# - exception when using public static variables in public static class -


When I tried to use a static variable, with some public static variable near a public static class The exception was threw an exception to typing the beginner for 'EM_Image.staticvariables'.

Why? And how can I solve it?

  public static class staticvariables {public static string image_source = "ahmed"; Public static bitmap b = new bitmap (image_source); Public Static Int K_numcolors = 0; Public static int M_leastbits = 0; Public static bitmap image bio = null; Public stable color [,] RGB_NU = new color [B. Wide, B. height]; // Basic color public static color [,] new_RGB_byte = new color [b. Wide, B. height]; // 1 public static string after color compression [,] RGBbIT = new string [b. Wide, B. Heights, 3]; // Original images public static string [,] new 1_rgbbt = new string [b. With, b. Heights, 3]; // Private zeros after compression 1) bt_Browse_Click (Object Sender, System.Windows.RoutedEventArgs e) {browse.ShowDialog (); Direction_text.Text = Browse. Filename; Staticvariables.image_source = browse.FileName; ImageSource imageSource = New Bitmap Image (New Yuri (Browse.Filename)); Pic_origin.Source = imageSource; }    

edit:

  public static string image_source = "ahmed"; Public static bitmap b = new bitmap (image_source);   

It looks like your default image_source is creating a null bitmap - exception is thrown when other stable properties start up And try to reach bitmap b - which is empty:

  public static color [,] RGB_NU = new color [b. With, b. height]; // Original color   

Your current design does not really satisfy your needs - It seems that instead of collecting the static properties you need the Singleton Frequency After saying this, you can initialize all the variables only with the null (that is, all those colors variables) and once you have valid input i.e. image_source ) All of them have to be updated / initialized.

Comments