[爆卦]include相反是什麼?優點缺點精華區懶人包

為什麼這篇include相反鄉民發文收入到精華區:因為在include相反這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者ymzk (127.0.0.1)看板C_and_CPP標題[分享] 無聊寫的BMP檔顏色相反處理...


前情提要 : BMP是個圖檔, 而BMP前面有54byte是記錄著裡面的一些屬性而
後面的東西皆為圖片的資料(24位元全彩圖是這樣的格式)
檔頭+屬性介紹共54byte由於我寫的程式是採用24bit全彩圖(未壓縮)
所以後面沒有調色盤的資料, 直接就是圖片內容, 而內容則
RGBRGBRGB....這樣一直排列下去一個R或G或B使用1byte
而互補色(顏色相反公式為 (255-r, 255-g, 255-b)), 所以輸出的檔案為前54byte照抄
後面所有東西到底之前都是 把他轉成數字 在用255去減去他 在輸出即可~

==========以下為CODE==========
//use Dev C++

#include <iostream>
#include <fstream> //存取檔案
#include <string>
using namespace std;

int main(int argc, char** argv) {
cout << "《BMP圖片顏色相反程式》" << endl;
cout << "此程式讀取之檔案限「*.BMP」格式且屬性為";
cout <<「未壓縮」、「24bit全彩」圖檔" << endl;
cout << "程式設計:ymzk" << endl;
while(true) {
string input_filename, output_filename;
cout << "請輸入要開啟的檔案:";
getline(cin, input_filename);
cout << "請輸入要儲存的檔案:";
getline(cin, output_filename);
fstream input, output;
input.open(input_filename.c_str(), ios::in | ios::binary);
output.open(output_filename.c_str(), ios::out | ios::binary);
cout << "處理中..." << endl;
unsigned char temp;
for(int i = 0l i < 54; i++) {
if(input.good()) {
input.read((char*)&temp, 1);
output.write((char*)&temp, 1);
}
else break;
}
while(input.good()) {
input.read((char*)&temp), 1);
temp = (char)(255 - (unsigned int)temp);
output.write((char*)&temp, 1);
}
input.close();
output.close();
cout << "已完成。" << endl;
}
return 0;
}

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.1.226.184
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1404390426.A.3C9.html
※ 編輯: ymzk (106.1.226.184), 07/03/2014 20:38:36
EdisonX:耶..其實你漏了蠻多考量的,不過作最基礎教材是還...ok 吧 07/03 21:17
EdisonX:像是 each row alignment to 4's multiple 就沒考量. 07/03 21:20
xvid:cout 中文也挺酷的 07/03 21:29
Qbsuran:BMP是BGR吧 07/03 22:10
PUTOUCHANG:Bitwise NOT 比較好用 07/03 22:30
MOONRAKER:沒錯bitwise not卡實在 07/03 23:06
KevinR:一個byte一個byte處理為什麼要考慮alignment? 07/04 09:25
EdisonX:@KevinR 是吶,這樣連 offset 都處理掉了.. 07/04 11:32
q82419:for(int i = 0l i < 54; i++) 07/04 19:56
q82419:另外 何不考慮openCV 07/04 19:56
KevinR:現在影像處理作業可以用openCV囉? 07/04 20:04
suhorng:建議不要習慣數字開頭加 0,上次有人就這麼做,結果……  07/04 22:04
xvid:變八進位 07/04 22:34
prismwu:00000000000000O0000000O000000000000O000000O000OOOOOOOO 07/04 22:41
bibo9901:他應該是把分號打成小寫L而已 ...XD 07/04 23:56
Killercat:單單寫這個來講OpenCV不會比較快 :D 07/05 19:21

你可能也想看看

搜尋相關網站