| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 399 人关注过本帖
标题:错误到底在哪里啊?
只看楼主 加入收藏
努力学编程
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-8-25
收藏
 问题点数:0 回复次数:0 
错误到底在哪里啊?

#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
void main()
{
/* BMP文件头 */
typedef struct
{
unsigned short bfType; /* 文件类型 */
unsigned long bfSize; /* 文件大小 */
unsigned short bfReserved1; /* 保留位 */
unsigned short bfReserved2; /* 保留位 */
unsigned long bfOffBits; /* 数据偏移位置 */
} HEAD;

/* BMP信息头 */
typedef struct
{
unsigned long biSize; /* 此结构大小 */
long biWidth; /* 图像宽度 */
long biHeight; /* 图像高度 */
unsigned short biPlanes; /* 调色板数量 */
unsigned short biBitCount; /* 每个象素对应的位数,24:24位图,32:带alpha通道的24位图 */
unsigned long biCompression; /* 压缩 */
unsigned long biSizeImage; /* 图像大小 */
long biXPelsPerMeter;/* 横向分辨率 */
long biYPelsPerMeter;/* 纵向分辨率 */
unsigned long biClrUsed; /* 颜色使用数 */
unsigned long biClrImportant; /* 重要颜色数 */
}BMPINFOHEADER;

FILE *file ;
HEAD bmpFile;
BMPINFOHEADER bmpInfo;


/* 打开文件 */
file = fopen("LENNA.BMP", "rb");
if (file== NULL)
{
printf(" openning error\n");
}
/* 读入文件头 */
fread(&bmpFile, sizeof(HEAD)-2,1, file);/* sizeof(HEAD)-2是为了使内存对齐*/

if (bmpFile.bfType != 0x4D42)
{
printf(" reading error!!!");
}
printf("%x\n",bmpFile.bfType); /* 验证文件类型 */
printf("%ld\n",bmpFile.bfSize);
printf("%ld\n",bmpFile.bfOffBits);

/* 读信息头 */
fread(&bmpInfo, sizeof(BMPINFOHEADER), 1, file);
printf("%ld\n",bmpInfo.biSizeImage);
printf("%d\n",bmpInfo.biWidth);
printf("%d\n",bmpInfo.biHeight);
printf("%d\n",bmpInfo.biBitCount);

}
就是读一个位图的信息,我读的是一个512*512的灰度图象。

结果是:
4d42
4
-859045888
0
512
512
8

printf("%ld\n",bmpFile.bfSize);
printf("%ld\n",bmpFile.bfOffBits);
printf("%ld\n",bmpInfo.biSizeImage);
这三个怎么读的数据不对啊??是什么原因?

2007-08-28 10:19
快速回复:错误到底在哪里啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011703 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved