In my program you can save the project you're working on, containing information and images, I've been trying to save it to a single binary file, and up until a little while ago it worked, IDK what changed :/
Here's the save/open function:
_______________________
Expand|Select|Wrap|Line Numbers
- public static void Save(string fname)
- {
- int length = 0;
- byte[] bytes;
- BinaryWriter bw = new BinaryWriter(File.Open(fname, FileMode.Create));
- bw.Write(FileVersion);
- bw.Write(ProjectName);
- bw.Write(count_images);
- bw.Write(count_actors);
- bw.Write(count_areas);
- bw.Write(Images.Count-1);//images
- foreach (project_image pi in Images)
- {
- pi.bitmap.Save("tmp.jpeg",
- ImageFormat.Jpeg);
- bytes = File.ReadAllBytes("tmp.jpeg");
- length = bytes.Length;
- bw.Write(length);
- bw.Write(pi.ImageName);
- bw.Write(bytes);
- }
- File.Delete("tmp.jpeg");
- bw.Write(Actors.Count);//actors
- foreach (project_actor pa in Actors)
- {
- bw.Write(pa.Name);
- bw.Write(pa.Image);
- bw.Write(pa.Visible);
- }
- bw.Close();
- }
- public static ProjectLoadReturn Open(string fname)
- {
- ProjectLoadReturn plr = new ProjectLoadReturn();
- int c = 0;
- int l = 0;
- byte[] bytes;
- project_image pi;
- TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitma…
- BinaryReader br = new BinaryReader(File.Open(fname, FileMode.Open));
- if (br.ReadInt32() == FileVersion)
- {
- ProjectName = br.ReadString();
- count_images = (short)br.ReadInt32();
- count_actors = (short)br.ReadInt32();
- count_areas = (short)br.ReadInt32();
- c = br.ReadInt32();
- for (int i = 0; i < c; i += 1)
- {
- pi = new project_image();
- l = br.ReadInt32();
- pi.ImageName = br.ReadString();
- bytes = br.ReadBytes(l);
- pi.bitmap = (Bitmap)tc.ConvertFrom(bytes);
- Images.Add(pi);
- plr.Images.Add(pi.ImageName);
- pi = null;
- }
- }
- else
- plr.WrongVersion = true;
- br.Close();
- return plr;
- }
For some reason both variables c & l in the open function are astronomically high compared to where they should be eg; 1762000896 and 1701273965 respectively ; c should have been 2 and l should have been ALLOT lower.
I'm hoping this is just a stupid mistake on my part, I'm not TOO worried as this isn't a school thing or anything so I'm not on a time frame, but I'd like to continue working on my program!
Thanks for any help :D