作者 主題: C語言開啟BMP圖檔,存在txt文字檔後,再顯示問題  (閱讀 7013 次)

0 會員 與 1 訪客 正在閱讀本文。

sturobin427

  • 可愛的小學生
  • *
  • 文章數: 2
    • 檢視個人資料
原本我利用C語言開啟BMP圖檔,然後把BMP數值存在txt文字檔中,再用printf顯示出來

但我想先把數值先存起來,之後再顯示出來,就是不要用到txt檔,想請高手大大們能否幫我修改一下,我做了很多天、也想了很多天,都弄不出來,拜託了 :'(,謝謝

原本我的程式動作: 先輸入檔案編號(EX: 圖檔為1.bmp, 所以輸入 1  ) -> 接著存在txt檔 -> 再去讀取txt檔,顯示

圖檔網址(GOOGLE硬碟):https://docs.google.com/file/d/0BzQNGwr-AzldZnF3ZFI3Ri0zeDA/edit

下面是我的原始碼

---

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
int i,j,x,y; //指標


main()
{
//=========================================讀BMP
BITMAPFILEHEADER bmpfile1;
BITMAPINFOHEADER bmpinfo1;
RGBQUAD File1_rgb[256];
byte *I;
FILE *f;
//=========================================file
char image_name[20];

printf("image編號:");
scanf("%d",&i);
sprintf(image_name, "CCD(%d).bmp", i);

f=fopen(image_name,"rb");
fread((char*)&bmpfile1,sizeof(BITMAPFILEHEADER),1,f);
fread((char*)&bmpinfo1,sizeof(BITMAPINFOHEADER),1,f);
fread( (char*)&File1_rgb, sizeof(File1_rgb), 1, f);

I=(byte*)malloc(sizeof(byte)*(bmpinfo1.biHeight*bmpinfo1.biWidth));
fread(I, sizeof(byte)*(bmpinfo1.biHeight)*(bmpinfo1.biWidth), 1, f);


FILE *fp_w = fopen("data_out.txt", "w");
int i,j;
for(i=0;i<bmpinfo1.biWidth;i++){
for(j=0;j<bmpinfo1.biHeight;j++){
    fprintf(fp_w, "%3d ", *(I+(bmpinfo1.biWidth)*j+i));
    if(i==bmpinfo1.biWidth-1)
    fprintf(fp_w, "\n ");
}}
fclose(fp_w);
fclose(f);

system("PAUSE");
}
« 上次編輯: 2013-12-13 21:27 由 sturobin427 »

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
原本我利用C語言開啟BMP圖檔,然後把BMP數值存在txt文字檔中,再用printf顯示出來

但我想先把數值先存起來,之後再顯示出來,就是不要用到txt檔,想請高手大大們能否幫我修改一下,我做了很多天、也想了很多天,都弄不出來,拜託了 :'(,謝謝

原本我的程式動作: 先輸入檔案編號(EX: 圖檔為1.bmp, 所以輸入 1  ) -> 接著存在txt檔 -> 再去讀取txt檔,顯示

圖檔網址(GOOGLE硬碟):https://docs.google.com/file/d/0BzQNGwr-AzldZnF3ZFI3Ri0zeDA/edit

下面是我的原始碼

(略)
}

什麼地方弄不出來?
要不要先將讀到的資料(header)印出來看看有沒有讀對資料

zelda

  • 憂鬱的高中生
  • ***
  • 文章數: 92
    • 檢視個人資料
不存在硬碟裡
那就保留在記憶體囉
不然…我想不到還有哪裡可以放

再不然用opencv就可以直接開圖檔

sturobin427

  • 可愛的小學生
  • *
  • 文章數: 2
    • 檢視個人資料
請問大大我要怎存放在記憶體內,再讀出來?