public void ImageStructExSerialize(ImageStructEx ise)
            {
                string folder = DataFolder;

                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }

                string path  = ImageFilePath(ise.data.meterType, ise.resourceId);
                var    array = serial.ImageToString(ise.bitmap);

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                using (BinaryWriter binWriter
                           = new BinaryWriter(File.Open(path, FileMode.Create))) {
                    binWriter.Write(array);
                }

                string structpath
                    = ImageDataPath(ise.data.meterType, ise.data.resourceid);

                using (var file = File.OpenWrite(structpath)) {
                    var writer = new BinaryFormatter();
                    writer.Serialize(file, ise.data);
                }
            }
        public PrettySMeterHelpers(Thetis.Console console)
        {
            m_console = console;
            m_helper  = new metering.helpers(console);
            test();

            ImageStructEx img = new ImageStructEx();

            img.data.scaleKind = MeterScaleKinds.log_scale;
            img.bitmap         = helpers.makeBitmap(Resources.PPM);
        }
            private static ImageStructEx defaultImageStruct()
            {
                var ret = new ImageStructEx();

                ret.data.meterType  = MeterTypes.SMeter;
                ret.data.scaleKind  = MeterScaleKinds.log_scale;
                ret.data.resourceid = BuiltInMeters.Original;
                ret.bitmap          = makeBitmap(
                    Thetis.Properties.Resources.NewVFOAnalogSignalGauge);
                return(ret);
            }
        private void test()
        {
            ImageStructEx bkg = new ImageStructEx();

            bkg.data.fileName  = "test";
            bkg.resourceId     = BuiltInMeters.Blue;
            bkg.data.scaleKind = MeterScaleKinds.log_scale;
            m_helper.ImageStructExSerialize(bkg);

            ImageStructEx imgbak = m_helper.ImageStructExDeSerialize(
                bkg.data.meterType, bkg.data.resourceid);

            Debug.Assert(imgbak.data.fileName == "test");
            Debug.Assert(imgbak.bitmap != null);
            Debug.Assert(imgbak.data.resourceid == BuiltInMeters.Blue);
            Debug.Assert(imgbak.data.scaleKind == MeterScaleKinds.log_scale);
        }
            public ImageStructEx ImageStructExDeSerialize(
                MeterTypes mt, BuiltInMeters bim = BuiltInMeters.Original)
            {
                ImageStructEx ret    = new ImageStructEx();
                string        folder = DataFolder;

                if (!System.IO.Directory.Exists(folder))
                {
                    return(defaultImageStruct());
                }

                string imgpath = ImageFilePath(mt, bim);

                if (!System.IO.File.Exists(imgpath))
                {
                    return(defaultImageStruct());
                }

                byte[] imgarray  = File.ReadAllBytes(imgpath);
                byte[] dataarray = File.ReadAllBytes(ImageDataPath(mt, bim));

                using (var ms = new MemoryStream(imgarray)) {
                    ret.bitmap = new Bitmap(ms);
                }

                string structpath = ImageDataPath(mt, bim);

                if (!File.Exists(structpath))
                {
                    return(ret);
                }
                using (var file = File.OpenRead(structpath)) {
                    var reader = new BinaryFormatter();

                    ret.data = (ImageStruct)reader.Deserialize(file);
                }

                return(ret);
            }