Binary









How do I use Binary
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: GameController.cs Copy
73  public void Save(){
74   FileStream file = null;
75
76   try{
77    BinaryFormatter bf = new BinaryFormatter();
78    file = File.Create(Application.persistentDataPath + "/data.dat");
79
80    if(file != null){
81     data.SetIsGameStartedFirstTime(isGameStartedFirstTime);
82     data.SetIsMusicOn(isMusicOn);
83     data.SetCoins (coins);
84     data.SetWeaponLevel (weaponLevel);
85     bf.Serialize(file, data);
86    }
87
88   }catch(Exception e){
89    Debug.LogException (e, this);
90   }finally{
91    if(file != null){
92     file.Close ();
93    }
94   }
95  }
File name: GameController.cs Copy
97  public void Load(){
98   FileStream file = null;
99
100   try{
101    BinaryFormatter bf = new BinaryFormatter();
102    file = File.Open(Application.persistentDataPath + "/data.dat", FileMode.Open);
103    data = bf.Deserialize(file) as GameData;
104   }catch(Exception e){
105    Debug.LogException (e, this);
106   }finally{
107    if(file != null){
108     file.Close ();
109    }
110   }
111  }
File name: GameController.cs Copy
82  public void Save(){
83   FileStream file = null;
84
85   try{
86    BinaryFormatter bf = new BinaryFormatter();
87    file = File.Create(Application.persistentDataPath + "/data.dat");
88
89    if(data != null){
90     data.SetIsMusicOn(isMusicOn);
91     data.SetIsGameStartedFirstTime(isGameStartedFirstTime);
92     data.SetHighScore(highscore);
93     data.SetLevels(levels);
94     bf.Serialize(file, data);
95    }
96
97   }catch(Exception e){
98    Debug.LogException (e, this);
99   }finally{
100    if(file != null){
101     file.Close ();
102    }
103   }
104  }
File name: GameController.cs Copy
106  public void Load(){
107   FileStream file = null;
108
109   try{
110    BinaryFormatter bf = new BinaryFormatter();
111    file = File.Open(Application.persistentDataPath + "/data.dat", FileMode.Open);
112    data = bf.Deserialize(file) as GameData;
113
114   }catch(Exception e){
115    Debug.LogException (e, this);
116   }finally{
117    if(file != null){
118     file.Close ();
119    }
120   }
121  }
File name: frmEnrollment.cs Copy
39   public frmEnrollment()
40   {
41    InitializeComponent();
42
43    face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
44             eye = new HaarCascade("haarcascade_eye.xml");
45             try
46             {
47                 string Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
48                 string[] Labels = Labelsinfo.Split('%');
49                 NumLabels = Convert.ToInt16(Labels[0]);
50                 ContTrain = NumLabels;
51                 string LoadFaces;
52
53                 for (int tf = 1; tf < NumLabels+1; tf++)
54                 {
55                     LoadFaces = "face" + tf + ".bmp";
56                     trainingImages.Add(new Image(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
57                     labels.Add(Labels[tf]);
58                 }
59
60             }
61             catch(Exception e)
62             {
63                 MessageBox.Show("Nothing in binary database, please add at least a face", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
64             }
65
66   }
File name: MainForm.cs Copy
47         public FrmPrincipal()
48         {
49             InitializeComponent();
50
51             face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
52             eye = new HaarCascade("haarcascade_eye.xml");
53             try
54             {
55                 string Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
56                 string[] Labels = Labelsinfo.Split('%');
57                 NumLabels = Convert.ToInt16(Labels[0]);
58                 ContTrain = NumLabels;
59                 string LoadFaces;
60
61                 for (int tf = 1; tf < NumLabels+1; tf++)
62                 {
63                     LoadFaces = "face" + tf + ".bmp";
64                     trainingImages.Add(new Image(Application.StartupPath + "/TrainedFaces/" + LoadFaces));
65                     labels.Add(Labels[tf]);
66                 }
67
68             }
69             catch(Exception e)
70             {
71                 MessageBox.Show("Nothing in binary database, please add at least a face", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
72             }
73
74         }

Download file with original file name:Binary

Binary 116 lượt xem

Gõ tìm kiếm nhanh...