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