標題:

如何用C++開啟圖片檔(.RAW)~20點(視覺密碼-專題)

發問:

有人可以教我程式碼怎麼寫嗎? 我的軟體是Microsoft Visual C++ 6.0 麻煩請教各位大大!? 灰階的圖片檔唷~不用彩色的! 請不要貼假檔!知識+的我都看過了~ 請不要亂複製錯的給我!謝謝! 執行成功20點就你的! 更新: 請問要怎麼開啟押?! 因為我再按RUN的時候出現結果他說無法開啟! 能否能再詳細一點! 因為我不是學的很好! 謝謝你!!!

最佳解答:

#include #include using namespace std; class image { int width; int height; public: unsigned char* lum; void read_image(); void show_image(); }; void image::read_image() { char fname[20]; cout > fname; ifstream inputf; inputf.open(fname,ios::binary); if(!inputf.is_open()) cout > width; cout > height; lum = new unsigned char[width * height]; inputf.read((char*) lum, height * width * sizeof(char)); inputf.close(); } void image::show_image() { char fname[20]; cout > fname; ofstream outputf; outputf.open(fname,ios::binary); outputf.write((char*) lum, width*height*sizeof(char)); outputf.close(); } void main () { image p1; p1.read_image(); //此時p1是你從.raw檔中讀出的資料 你可以對它們做處理 p1.read_image(); } 2007-07-28 17:09:48 補充: main的部份修改一下,另外讀檔要加上副檔名 void main () { image p1; p1.read_image(); //此時p1是你從.raw檔中讀出的資料 你可以對它們做處理 p1.show_image(); } 2007-07-29 11:49:28 補充: 如果你說執行程式出現的是"can't open!!" 那首先你先看一下你的main()的部分有沒有更新成我之後補充的那段 稍微跟你解釋一下: p1.read_image(); 這代表我呼叫read_image()函式,我這函式寫的意思代表說你要先讀檔(ex:image.raw)之後再輸入寬跟高的值。 如果輸入以上這三個資訊後還是顯示"can't open!!",那看一下你圖檔有沒有放好,我是預設放在跟你的程式碼(*.cpp)同一層資料夾裡面 p1.show_image(); 這代表呼叫show_image這函式,主要是輸出結果影像,所以你必須先給它你要存的檔案名稱ex:result.raw 2007-07-29 11:49:35 補充: 其實要讀.raw檔不難,只要會開檔(因為是binary檔,所以ios設成binary)、讀檔(f.read())、寫檔(f.write)這樣就可以做到了

其他解答:

有必要連問兩題一樣的嗎??@@"7C4CB18E23D7C5B7

arrow
arrow
    創作者介紹
    創作者 keithtyrantho 的頭像
    keithtyrantho

    許阿松

    keithtyrantho 發表在 痞客邦 留言(0) 人氣()