【框架-MFC】CObject 继承对象的序列化存储与读取
来源:互联网 发布:mac散热器声音大怎么办 编辑:程序博客网 时间:2024/06/04 23:33
头文件
#pragma once#define IPL_DEPTH_24U 24#define IPL_DEPTH_20U 20class C24SCT: public CObject {public:C24SCT(void);~C24SCT(void);DECLARE_SERIAL(C24SCT) private:CString strFilePath; //保存文件的路径long nSize; //C24SCT结构大小 int nChannels; //图像通道数量 int nDepth; //图像位深 int nWidth; //图像宽度 int nHeight; //图像高度int nVersion;//图像版本 char *pImageData; public://Attributeslong Size();int Width();int Height();int Depth();int Version();CString GetPath();void SetPath(CString filePath);public://Methodvoid Read();void Write();void New(int height ,int width); C24SCT& operator= (C24SCT & obj ) ;};实现文件
#include "StdAfx.h"#include "C24SCT.h"IMPLEMENT_SERIAL(C24SCT, CObject, 1) C24SCT::C24SCT(void){nWidth =0 ;nHeight = 0;nDepth = 24;nVersion = 2016;pImageData = NULL;nChannels =1;}C24SCT::~C24SCT(void){if (pImageData!=NULL){//delete [] imageData;pImageData= NULL;}nWidth =0 ;nHeight = 0;}void C24SCT::Read(){CFile file;CFileException fe;//以读方式打开文件if(!file.Open(strFilePath,CFile::modeRead,&fe)){fe.ReportError();return;}//构建CArchive 对象CArchive ar(&file,CArchive::load);ar >>nWidth>>nHeight>>nDepth>>nVersion;CString str;str.Format(_T("width %d height %d\n"),nWidth,nHeight);OutputDebugString(str);New(nHeight ,nWidth);for(DWORD i = 0; i < nWidth*nHeight*3; i++)ar>>(pImageData[i]);ar.Flush();//读完毕,关闭文件流ar.Close();file.Close();}void C24SCT::Write(){CFile file;CFileException fe;//以读方式打开文件if(!file.Open(strFilePath,CFile::modeWrite|CFile::modeCreate,&fe)){fe.ReportError();return;}//构建CArchive 对象CArchive ar(&file,CArchive::store);ar <<nWidth<<nHeight<<nDepth<<nVersion;CString str;str.Format(_T("width %d height %d"),nWidth,nHeight);OutputDebugString(str);for(DWORD i = 0; i < nWidth*nHeight*3; i++)ar<<(pImageData[i]);ar.Flush();//写完毕,关闭文件流ar.Close();file.Close();}void C24SCT::New( int height ,int width ){if (pImageData!=NULL){delete []pImageData;pImageData=NULL;}nHeight = height;nWidth = width;CString str;str.Format(_T("width %d height %d"),height,width);OutputDebugString(str);pImageData = new char[height*width*3];}long C24SCT::Size(){long nFilePathSize =0 ;if (strFilePath.GetLength() == 0){nFilePathSize = sizeof(CString);}else{nFilePathSize = sizeof(TCHAR) * strFilePath.GetLength() ;}long pImageDataSize = 0 ;if(pImageData == NULL){pImageDataSize = sizeof(pImageData);}else{pImageDataSize = nWidth*nHeight*3*sizeof(char);}nSize = sizeof(int)*5 + sizeof(long)+pImageDataSize+nFilePathSize;return nSize;}int C24SCT::Width(){return nWidth;}int C24SCT::Height(){return nHeight;}int C24SCT::Depth(){return nDepth;}int C24SCT::Version(){return nVersion;}C24SCT& C24SCT::operator= (C24SCT &obj ) {SetPath(obj.GetPath());return *this;}CString C24SCT::GetPath(){return strFilePath;}void C24SCT::SetPath(CString filePath ){strFilePath = filePath;}
调用-写
C24SCT new24file;new24file.New(width,height);new24file.SetPath(L"C:\\tmp.tmp");new24file.Write();调用-读
C24SCT new24file;new24file.SetPath(L"C:\\tmp.tmp");new24file.Read();
0 0
- 【框架-MFC】CObject 继承对象的序列化存储与读取
- MFC 的根--CObject
- Java序列化对象的存储和读取
- Java序列化对象的存储和读取
- Java —— 序列化对象的存储和读取
- NSCoding序列化存储与读取
- Java源码——对象序列化(对象的存储及读取)(Object Serialization)
- python对象的存储与读取
- Android序列化的存储和读取
- [MFC]对象序列化
- MFC对象序列化
- 程序调试--CObject对象的串行化
- 程序调试--CObject对象的并行化
- 程序调试--CObject对象的串行化
- 基于对象序列化实现对象属性的保存与读取
- .net序列化与反序列化——提供多次存储对象集后读取不完全解决方案
- 如何精通MFC-----CObject类的理解
- 如何精通MFC-----CObject类的理解
- 关于Toolbar的折腾(结合Fragment使用)
- 番茄工作法总结
- Hbase整合hive数据库
- tinyint(1) 跟 tinyint(n) n>1 不一样
- nginx按小时切割日志
- 【框架-MFC】CObject 继承对象的序列化存储与读取
- AsyncTask
- 几种sql*plus常用的命令更改账户密码
- popupwindow中ListView item点击事件无效的解决方案
- ZooKeeper相关错误的解决
- C++ typedef用法小结(挺好)
- 欢迎使用CSDN-markdown编辑器
- centos 7 mysql5.6笔记
- php简单工厂模式,工厂方法模式和抽象工厂模式比较