中易网

c++ 如何读取raw图片

答案:1  悬赏:40  
解决时间 2021-01-16 06:54
c++ 如何读取raw图片
最佳答案
如果你技术可以,这个就够了 

raw 头文件可以去网上下载 

 参考代码:

# #include "Raw.h"   

#    

# #ifdef _DEBUG   

# #undef THIS_FILE   

# static char THIS_FILE[]=__FILE__;   

# #define new DEBUG_NEW   

# #endif   

#    

# //////////////////////////////////////////////////////////////////////   

# // Construction/Destruction   

# //////////////////////////////////////////////////////////////////////   

#    

# CRaw::CRaw()       

# //无参数初始化,不分配内存.   

# {   

#     m_sizeImage= CSize(0,0);   

#     m_pBuff= NULL;   

#    

# }   

#    

# CRaw::CRaw(CSize sizeImage)   

# //初始化,指定图像大小,并分配相应的内存.   

# {   

#     m_sizeImage= sizeImage;   

#     m_nWidth = m_sizeImage.cx;   

#     m_nHeight = m_sizeImage.cy;   

#     m_pBuff= new BYTE[sizeImage.cy*sizeImage.cx];   

#     memset(m_pBuff, 0, sizeImage.cy*sizeImage.cx*sizeof(BYTE));   

# }   

#    

# CRaw::CRaw(CSize sizeImage, BYTE *pBuff)   

# //初始化,sizeImage:图像大小,pBuff:指向像素位的指针.   

# {   

#     m_sizeImage= sizeImage;   

#     m_nWidth = m_sizeImage.cx;   

#     m_nHeight = m_sizeImage.cy;   

#     m_pBuff= new BYTE[sizeImage.cy*sizeImage.cx];   

#     memcpy(m_pBuff, pBuff, sizeImage.cy*sizeImage.cx*sizeof(BYTE));   

# }   

#    

# CRaw::~CRaw()   

# {   

#     if (m_pBuff!=NULL)   

#         delete m_pBuff;   

#    

# }   

#    

# //下面是从文件的路径读写RAW格式的图像, 这里是文件存储路径   

#    

# BOOL CRaw::ReadFromFile(CString strFilename)   

# //从文件中读取Raw图像,strFilename:源文件的完整路径和文件名.   

# {   

#     CFile file;   

#     CFileException ex;   

#     int nWidth, nHeight;   

#    

#     CString strError1= "文件打开错误!";   

#     CString strError2= "非正确的raw格式文件!";   

#    

#     if (!file.Open(strFilename, CFile::modeRead, &ex)){   

#         ex.ReportError();   

#         return FALSE;   

#     }   

#    

#     if (file.Read(&nHeight, sizeof(int))!=sizeof(int)){   

#         AfxMessageBox(strError1, MB_OK|MB_ICONEXCLAMATION);   

#         file.Close();   

#         return FALSE;   

#     }   

#    

#     if (file.Read(&nWidth, sizeof(int))!=sizeof(int)){   

#         AfxMessageBox(strError1, MB_OK|MB_ICONEXCLAMATION);   

#         file.Close();   

#         return FALSE;   

#     }   

#    

#     m_sizeImage.cy= nHeight;   

#     m_sizeImage.cx= nWidth;   

#     m_nHeight = nHeight;   

#     m_nWidth = nWidth;   

#     m_pBuff= new BYTE[nHeight*nWidth];   

#    

#     if (file.ReadHuge(m_pBuff, nHeight*nWidth)!=(nHeight*nWidth)){   

#         AfxMessageBox(strError2, MB_OK|MB_ICONEXCLAMATION);   

#         file.Close();   

#         return FALSE;   

#     }   

#    

#     file.Close();   

#     return TRUE;   

# }   

#    

#    

# BOOL CRaw::WriteToFile(CString strFilename)   

# //将Raw图像写到文件, strFilename:目标文件的完整路径和文件名.   

# {   

#     CFile file;   

#     CFileException ex;   

#     int nHeight, nWidth;   

#    

#     nHeight= m_sizeImage.cy;   

#     nWidth= m_sizeImage.cx;   

#    

#     if (!file.Open(strFilename, CFile::modeCreate|CFile::modeWrite, &ex)){   

#         ex.ReportError();   

#         return FALSE;   

#     }   

#    

#     file.Write(&nHeight, sizeof(int));   

#     file.Write(&nWidth, sizeof(int));   

#    

#     file.WriteHuge(m_pBuff, nHeight*nWidth*sizeof(BYTE));   

#    

#     file.Close();   

#    

#     return TRUE;   

#    

# }   

#    

# // 这下面是RAW图像格式和BITMAP图像格式的相互间的交互转换   

# CDib* CRaw::GetDib()   

# //由Raw图像获得Dib位图.   

# {   

#     CDib* pDib= new CDib(m_sizeImage, 8);   

#     BYTE* pColorTable= (BYTE*) pDib->m_lpvColorTable;   

#     BYTE* pImage;   

#     CSize sizeDib;   

#     int nX, nY;   

#    

#     if (m_sizeImage.cx%4==0)   

#         sizeDib.cx=m_sizeImage.cx;   

#     else   

#         sizeDib.cx=((m_sizeImage.cx)/4+1)*4;   

#     sizeDib.cy=m_sizeImage.cy;   

#    

#     for (int i=0; i<256; i++){   

#         pColorTable[i*4]= i;   

#         pColorTable[i*4+1]= i;   

#         pColorTable[i*4+2]= i;   

#         pColorTable[i*4+3]= 0;   

#     }   

#    

#     pImage= new BYTE[sizeDib.cy*sizeDib.cx];   

#     memset(pImage, 0, sizeDib.cy*sizeDib.cx);   

#       

#     for (nY=0; nYm_lpImage= pImage;   

#     return pDib;   

# }   

#    

# BOOL CRaw::GetFromDib(CDib *pDib)   

# //由Dib位图获得Raw图像.   

# {   

#     int nX, nY;   

#     int nDibWidth;   

#     BYTE* pImage= pDib->m_lpImage;   

#    

#     if (pDib->m_lpBMIH->biBitCount!=8)   

#         return FALSE;   

#    

#     m_sizeImage= pDib->GetDimensions();   

#     m_nWidth = m_sizeImage.cx;   

#     m_nHeight = m_sizeImage.cy;   

#     if ( (m_sizeImage.cx%4)!=0 )   

#         nDibWidth= (m_sizeImage.cx/4+1)*4;   

#     else    

#         nDibWidth= m_sizeImage.cx;   

#    

#     m_pBuff= new BYTE[m_sizeImage.cx*m_sizeImage.cy];   

#    

#     for (nY=0; nYGetPosition();   

#     TRACE("CRaw::Serialize -- pos = %d
", dwPos);   

#     ar.Flush();   

#     dwPos = ar.GetFile()->GetPosition();   

#     TRACE("CRwa::Serialize -- pos = %d
", dwPos);   

#    

#     if(ar.IsStoring()) {   

#         Write(ar.GetFile());   

#     }   

#     else {   

#         Read(ar.GetFile());   

#     }   

# }   

#    

# //下面是从文件中读RAW图像,以及向文件中写RAW图像   

# BOOL CRaw::Write(CFile *pFile)   

# {   

#     int nHeight, nWidth;   

#     nHeight= m_sizeImage.cy;   

#     nWidth= m_sizeImage.cx;   

#    

#     try {   

#         pFile->Write(&nHeight, sizeof(int));   

#         pFile->Write(&nWidth, sizeof(int));   

#         pFile->WriteHuge(m_pBuff, nHeight*nWidth);   

#     }   

#     catch (CException *pe){   

#         pe->Delete();   

#         AfxMessageBox("File wirte error!", IDOK);   

#         return FALSE;   

#     }   

#    

#     return TRUE;   

# }   

#    

# BOOL CRaw::Read(CFile *pFile)   

# {   

#     int nHeight, nWidth;   

#    

#     try {   

#         pFile->Read(&nHeight, sizeof(int));   

#         pFile->Read(&nWidth, sizeof(int));   

#         m_nWidth = nWidth;   

#         m_nHeight - nHeight;   

#         m_sizeImage.cx= nWidth;   

#         m_sizeImage.cy= nHeight;   

#    

#         m_pBuff= new BYTE[nHeight*nWidth];   

#    

#         int nCount= pFile->ReadHuge(m_pBuff, nHeight*nWidth);   

#         if (nCount!=nWidth*nHeight)   

#             throw new CException;   

#     }   

#     catch (CException *pe){   

#         pe->Delete();   

#         AfxMessageBox("File read error!", IDOK);   

#         return FALSE;   

#     }   

#    

#     return TRUE;   

# }   

#    

#    

# void CRaw::Empty()   

# {   

#     if (m_pBuff!=NULL)   

#         delete m_pBuff;   

#     m_pBuff = NULL;   

#    

# }   

#    

# BOOL CRaw::IsEmpty()   

# {   

#     if(m_pBuff != NULL)   

#         return FALSE;   

#     return TRUE;   

# }
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
html中<table>和<asp:Tabel>有什么不一样啊
中铁物流集团(振兴西路沙县小吃旁)地址在哪,
世界上IQ前十名依次是?
平安物流(北安路84号1附近停车场)地址在哪,
描述EDA技术的基本特征及采用EDA技术数字系统
电容器相当于导线还是电阻
小雨10 ℃到7℃穿什么衣服
分光光度法
巴里坤哈萨克自治县土地矿产资源储备中心地址
水库水太深怎样调漂
如果村里农民放羊吃了别人的庄稼,还打人怎么
哪些怕台风,树儿见我把腰弯,照样子怎么写呀!
封闭图形一周的长度,是它的周长.______.(
苍茫是什么意思?
沈铁火车票代售处(前二道河子)地址有知道的么
推荐资讯
为什么相机里面K值越低越蓝,和实际的色温表
中石化(黑牛城道加油站)地址在什么地方,我要
广安职业技术学院有几个校区?
什么叫东方花香调香水??可以推荐点小清新的
高频电炉一顿铁消耗多少电 中频电炉一吨消耗
华容小学地址在什么地方,我要处理点事
哪些企业有粮食进口配额?
推拿中的日试和泰试是什么?
兰蔻的粉水和蓝水有什么区别?混合型皮肤
500斤小伙离世 肥胖会给人们带来哪些烦恼
我老婆外公在湖南永州道县有几千斤野生放养的
淘宝买家拍下后把价改太低了会有什么后果?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?