YASUDA'S BLOG
CとC++の簡単な画像プログラミング
スポンサーサイト
0
この広告は60日以上更新がないブログに表示されております。
新しい記事を書くことで広告を消すことができます。
2011.03.05 Saturday
-
-
-
by スポンサードリンク
簡単な画像を扱うクラスの実装4 画像の読み込みと書き込み
0
// ヘッダーファイルの追加
#include
/****************************************************************************/
// 画像の読み込み
bool CBmp::Read(const char *path)
{
// 画像の廃棄
Destroy();
// ファイル情報格納領域
char fhead[32];
// ファイル情報オフセット
int foffset[8] = {0,2,6,8,10,0,0,0};
// 読み込むファイルを開く
ifstream is(path,ios::in | ios::binary);
// ファイル情報の読み込み
is.read((char *)fhead,14);
// 画像ファイルか確認
unsigned short *us = (unsigned short *)((char *)fhead);
if(*us != 0x4d42)
return false;
// 画像情報の読み込み
is.read(m_Header,BMPHEADERSIZE);
// ビット情報格納領域のサイズを計算
unsigned long *ul = (unsigned long *)((char *)m_Header + m_Offset.i);
*ul = ScanBytes(GetWidth(),GetDepth()) * GetHeight();
// パレット情報の読み込み
int coentries = GetColorEntries();
if(GetColorEntries())
is.read((char *)m_Header + BMPHEADERSIZE,GetColorEntries() * 4);
// ビット情報格納領域の確保
if((m_Bits = new char[*ul]) == 0)
{
Destroy();
return false;
}
// ビット情報読み込み
is.read((char *)m_Bits,*ul);
return IsOK();
}
/****************************************************************************/
// 画像の書き出し
bool CBmp::Write(const char *path)
{
// 書き込む画像の確認
if(!IsOK())
return false;
// ファイル情報格納領域
char fhead[32];
// ファイル情報オフセット
int foffset[8] = {0,2,6,8,10,0,0,0};
// ファイル情報格納
unsigned short *us;
unsigned long *ul;
int i = 0;
// ファイルタイプ
us = (unsigned short *)((char *)fhead + foffset[i++]);
*us = 0x4d42;
// ファイルのサイズ
ul = (unsigned long *)((char *)fhead + foffset[i++]);
*ul = 14 + BMPHEADERSIZE + GetColorEntries() * 4 + ScanBytes(GetWidth(),GetDepth()) * GetHeight();
// 未使用情報
us = (unsigned short *)((char *)fhead + foffset[i++]);
*us = 0;
us = (unsigned short *)((char *)fhead + foffset[i++]);
*us = 0;
// ビット情報までのオフセット
ul = (unsigned long *)((char *)fhead + foffset[i++]);
*ul = 14 + BMPHEADERSIZE + GetColorEntries() * 4;
// 書き込むファイルを開く
ofstream os(path,ios::out | ios::binary);
// ファイル情報書き込み
os.write((char *)fhead,14);
// ヘッダー格納領域書き込み
os.write((char *)m_Header,BMPHEADERSIZE);
// パレット情報の書き込み
if(GetColorEntries())
os.write((char *)m_Header + BMPHEADERSIZE,GetColorEntries() * 4);
// ビット情報格納領域書き込み
os.write((char *)m_Bits,ScanBytes(GetWidth(),GetDepth()) * GetHeight());
return true;
}
/****************************************************************************/
JUGEMテーマ:
C言語
Tweet
Check
2011.02.28 Monday
BMP画像の処理
13:39
comments(0)
trackbacks(2)
by
yasuda
1
2
3
4
5
>|
next>>
このページの先頭へ▲
PR
calendar
S
M
T
W
T
F
S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<<
September 2011
>>
ランキング
パーツを表示するにはJavaScriptを有効にして下さい。[AD]
i2iアクセスランキング
i2i無料WEBパーツ
selected entries
簡単な画像を扱うクラスの実装4 画像の読み込みと書き込み
(02/28)
categories
BMP画像の処理
(5)
archives
2011年
2011年02月
(5)
recommend
素材満載 ブログで作る かんたんホームページ [CD-ROM付き]
(JUGEMレビュー »)
浅岡 省一
links
美少女フィギュア画像ギャラリー
agroman
JUGEM
User Template File
モノコレ
トラックバックBOX
カラメルでお買い物!
profile
yasuda
書いた記事数:5 最後に更新した日:2011/02/28
search this site.
others
管理者ページ
RSS1.0
Atom0.3
mobile
powered