RAW文件的读取

1.RAW结构是纯像素数据文件,里面只有每个像素的值,没有文件头、调色板等数据,所以要想正确显示一个RAW文件图像,必须人工指定它的长、宽和像素深度。
2.每个像素根据格式不同占有不同的字节,如8位256色每个像素占一个字节;24位真彩色每个像素占三个字节。
3.要自己写,注意:
(1)函数要有此RAW文件的长、宽和像素深度三个参数,从而得到BMP文件头,存入strBMP[]的前面;
(2)函数里把读进来的RAW文件数据strRaw[]里的数据进行行反转放入strBMP[]中文件头之后,即把第length-1-i行(从第0行开始记,i从0开始)的数据放到第i行,而每行里的数据不变。这样做是因为BMP文件里的像素数据是从最后一行即length-1开始的。
(3)使用显示BMP文件的函数来显示此strBMP[]里的图像文件。

 

 

  
  
  
1 参考代码:
2 # #include " Raw.h "
3 #
4 # #ifdef _DEBUG
5 # #undef THIS_FILE
6 # static char THIS_FILE[] = __FILE__;
7 # #define new DEBUG_NEW
8 # #endif
9 #
10 # / /
11   # // Construction/Destruction
12   # / /
13   #
14 # CRaw::CRaw()
15 # // 无参数初始化,不分配内存.
16 # {
17 # m_sizeImage = CSize( 0 , 0 );
18 # m_pBuff = NULL;
19 #
20 # }
21 #
22 # CRaw::CRaw(CSize sizeImage)
23 # // 初始化,指定图像大小,并分配相应的内存.
24 # {
25 # m_sizeImage = sizeImage;
26 # m_nWidth = m_sizeImage.cx;
27 # m_nHeight = m_sizeImage.cy;
28 # m_pBuff = new BYTE[sizeImage.cy * sizeImage.cx];
29 # memset(m_pBuff, 0 , sizeImage.cy * sizeImage.cx * sizeof (BYTE));
30 # }
31 #
32 # CRaw::CRaw(CSize sizeImage, BYTE * pBuff)
33 # // 初始化,sizeImage:图像大小,pBuff:指向像素位的指针.
34 # {
35 # m_sizeImage = sizeImage;
36 # m_nWidth = m_sizeImage.cx;
37 # m_nHeight = m_sizeImage.cy;
38 # m_pBuff = new BYTE[sizeImage.cy * sizeImage.cx];
39 # memcpy(m_pBuff, pBuff, sizeImage.cy * sizeImage.cx * sizeof (BYTE));
40 # }
41 #
42 # CRaw:: ~ CRaw()
43 # {
44 # if (m_pBuff != NULL)
45 # delete m_pBuff;
46 #
47 # }
48 #
49 # // 下面是从文件的路径读写RAW格式的图像, 这里是文件存储路径
50 #
51 # BOOL CRaw::ReadFromFile(CString strFilename)
52 # // 从文件中读取Raw图像,strFilename:源文件的完整路径和文件名.
53 # {
54 # CFile file;
55 # CFileException ex;
56 # int nWidth, nHeight;
57 #
58 # CString strError1 =
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值