Example #1
0
        /// <summary>
        /// 创建默认实例
        /// </summary>
        private void CreateDefaultInstance()
        {
            if (string.IsNullOrEmpty(imagePath))
            {
                ShowListInfo("图片路径为空!");
                return;
            }
            if (File.Exists(imagePath) == false)
            {
                ShowListInfo("图片路径不存在!");
                return;
            }
            myImageObj               = new CImageInfo();
            myImageObj.CreateTime    = DateTime.Now.ToString("hh:MM:ss.fff");
            myImageObj.ImageID       = 0;
            myImageObj.ImageName     = "TestImage";
            myImageObj.SerializeType = SerializeTypeEnum.BIT;
            Rectangle rect          = hWindowControl1.ImagePart;
            HTuple    imagefilepath = imagePath;

            HOperatorSet.ReadImage(out myImageObj.ho_Image, imagefilepath);

            HTuple width, height;

            HOperatorSet.GetImageSize(myImageObj.ho_Image, out width, out height);
            rect.X      = 0;
            rect.Y      = 0;
            rect.Width  = width.I;
            rect.Height = height.I;
            hWindowControl1.ImagePart = rect;
        }
Example #2
0
        /// <summary>
        /// Soap反序列化器
        /// </summary>
        private void SoapDeserialize()
        {
            FileStream fileStream = File.OpenRead(filePath);

            try
            {
                IFormatter formatter = (IFormatter)Activator.CreateInstance(typeof(SoapFormatter));
                fileStream.Position = 0;
                myImageObj          = (CImageInfo)formatter.Deserialize(fileStream);
            }
            finally
            {
                if (fileStream != null)
                {
                    ((IDisposable)fileStream).Dispose();
                }
            }
        }
Example #3
0
        /// <summary>
        /// 反序列化加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_DeserializeLoad_Click(object sender, EventArgs e)
        {
            if (File.Exists(filePath) == false)
            {
                ShowListInfo("文件不存在,将创建默认实例!");
                CreateDefaultInstance();
                ShowInstanceInfo();
                return;
            }
            ShowListInfo("开始执行反序列化");
            Stopwatch sw = new Stopwatch();

            sw.Restart();
            if (myImageObj != null)
            {
                myImageObj = null;
            }
            switch (serializeType)
            {
            case SerializeTypeEnum.BIT:
                BinaryDeserialize();
                break;

            case SerializeTypeEnum.XML:
                SoapDeserialize();
                break;

            case SerializeTypeEnum.JSON:

                break;

            default:
                break;
            }

            // BinaryDeserialize();
            sw.Stop();
            ShowListInfo("序列化完成,耗时:" + sw.ElapsedMilliseconds.ToString());
            ShowInstanceInfo();
        }
Example #4
0
        /// <summary>
        /// 二进制反序列化器
        /// </summary>
        private void BinaryDeserialize()
        {
            FileStream fileStream = File.OpenRead(filePath);

            try
            {
                IFormatter formatter = (IFormatter)Activator.CreateInstance
                                           (typeof(BinaryFormatter));
                formatter.Context = new StreamingContext
                                        (StreamingContextStates.File | StreamingContextStates.Persistence);
                fileStream.Position = 0;
                myImageObj          = (CImageInfo)formatter.Deserialize(fileStream);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                    fileStream = null;
                }
            }
        }