C_and_CPP 板


LINE

影像的width跟height是藏在header阵列中 索引值18~25的地方 如 weight的资料记录在 header[18]~header[21] height的资料则记在 header[22]~height[25] 如果要读取 可参考下列code long width = (long)header[18] + ((long)header[19] << 8) + ((long)header[20] << 16) + ((long)header[21] << 24); long height = (long)header[22] + ((long)header[23] << 8) + ((long)header[24] << 16) + ((long)header[25] << 24); 其中 << 为位元运算子,做什麽用应该不用说明了吧! 其他BM size 你可以去网路上找一下资料 看header里面都放了什麽东西 之後再按格式取出并正确的组合 就可以读取你想要的资料了 ※ 引述《SiriusJinn (假斯汀)》之铭言: : 以下是读档的程式码 : #include <stdio.h> : #include <stdlib.h> : #include <windows.h> : int bmp_read(unsigned char *image, int xsize, int ysize, char *filename) : { : FILE *fp; : char fname_bmp[128]; : long i, j; : unsigned char *image_buf; : unsigned char header[54]; : image_buf = (unsigned char *)malloc((size_t)xsize*ysize*3); : if (image_buf == NULL) return -1; : sprintf(fname_bmp, "%s.bmp", filename); : if ((fp = fopen(fname_bmp, "rb")) == NULL) return -1; : fread(header, sizeof(unsigned char), 54, fp); : fread(image_buf, sizeof(unsigned char), (size_t)(long)xsize*ysize*3, fp); : fclose(fp); : for (i = 0; i < ysize; i++){ : for (j = 0; j < xsize; j++){ : *(image + xsize*(ysize-i-1) + j) : = *(image_buf + 3*(xsize*i +j) +2); : *(image + xsize*(ysize-i-1) + j + xsize*ysize) : = *(image_buf + 3*(xsize*i +j) +1); : *(image + xsize*(ysize-i-1) + j + xsize*ysize*2) : = *(image_buf + 3*(xsize*i +j) ); : } : } : free(image_buf); : return 0; : } : int main() : { : unsigned char *image; : int xsize = 512; : int ysize = 512; : image = (unsigned char *)malloc((size_t)xsize * ysize * 3); : if (image == NULL) : return -1; : bmp_read(image, xsize, ysize, "lena.bmp"); : free(image); : } : 想请问如果我想把一些资料如 BM size width height 输出在萤幕的话 : printf该怎麽写呢?我read的部份有把 file-header 跟 information-header : 存进来了吗? : 绿色部份的作用是什麽,可否帮解释一下! : 感谢! --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.118.7.163
1F:→ kvykn:好像回错问题了XD 06/16 21:18
2F:→ VictorTom:可以用 *( (long*) (&header[18]) ) 吗....@_@" 06/16 21:34
3F:→ VictorTom:啊, 这样在大印弟安感觉好像会有问题....Orz 06/16 21:34
4F:推 wa120:推 06/16 21:52
5F:推 SiriusJinn:感谢! 06/16 22:30
6F:→ kvykn:printf("image width:%d\n", (int)width);其实才是问题解答 06/16 23:23
7F:→ kvykn:回VT:不行。hader纪录顺序是低位至高位。 举个例说明 06/16 23:28
8F:→ kvykn:若十进制数字为12345678好了,header储存此数字的顺序为 06/16 23:31
9F:→ kvykn:header[18]=78 header[19]=56 header[20]=34 header[21]=12 06/16 23:32
10F:→ kvykn:以上只是举例说明,实际上是二进制才对。 06/16 23:34
11F:推 VictorTom:假设用0x12345678, header[18]=0x78, header[19]=0x56, 06/16 23:50
12F:→ VictorTom:以此类推的话, 在一般常见的小印弟安系统(如windows), 06/16 23:51
13F:→ VictorTom:不就用*( (long*) (&header[18]) )刚刚好吗?? 而且我记 06/16 23:51
14F:→ VictorTom:得也有直接写struct(alignment 1)直接read 54 bytes回 06/16 23:52
15F:→ VictorTom:来直接就对应好所有data member的呀@_@" 06/16 23:52
16F:→ kvykn:什麽小印弟安啊... 我不认识这个人啊 06/17 00:10
17F:推 VictorTom:little endian, 因为endian老不会拼, 所以总叫印弟安:) 06/17 00:13
18F:→ kvykn:刚看了一下,好像跟CPU硬体设计有关.且compile时要下参数 06/17 00:21
19F:→ kvykn:很麻烦内....而且我觉得程式不好看(←这才是重点) 06/17 00:22







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP