1个回答
展开全部
如果你技术可以,这个就够了
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; nY<m_sizeimage.cy; ny++)="" for="" (nx="0;" nx=""><m_sizeimage.cx; nx++)="" pimage[ny*sizedib.cx+nx]="m_pBuff[(m_sizeImage.cy-1-nY)*m_sizeImage.cx+nX];" pdib-="">m_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; nY<m_sizeimage.cy; ny++)="" for="" (nx="0;" nx=""><m_sizeimage.cx; nx++)="" m_pbuff[ny*m_sizeimage.cx+nx]="pImage[(m_sizeImage.cy-1-nY)*nDibWidth+nX];" return="" true;="" }="" void="" craw::serialize(carchive="" &ar)="" {="" dword="" dwpos;="" dwpos="ar.GetFile()-">GetPosition();
# TRACE("CRaw::Serialize -- pos = %d\n", dwPos);
# ar.Flush();
# dwPos = ar.GetFile()->GetPosition();
# TRACE("CRwa::Serialize -- pos = %d\n", 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;
# }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询