わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

デバイスコンテキストの色ビット数を取得する

デバイスコンテキスト(HDC)が対応する色ビット数は、 GetDeviceCaps()関数の第2引数にPLANESを渡す事で取得できます。

デバイスコンテキストの色ビット数を取得する
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
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <windows.h>
 
 
 
/*
    デバイスコンテキストの色ビット数を取得する
*/
int _tmain
(
      int argc
    , _TCHAR* argv[]
)
{
    // 標準出力にユニコード出力する
    setlocale( LC_ALL, "Japanese" );
 
    // デバイスコンテキストの取得
    HDC hDC = ::GetDC( NULL );
 
    // デバイスコンテキストが対応する色数を取得する
    int iBitsInAPixel = ::GetDeviceCaps( hDC, PLANES ) * GetDeviceCaps( hDC, BITSPIXEL );
 
    // 色数を表示
    std::wcout << L"デバイスコンテキストの色ビット数 = " << iBitsInAPixel << std::endl;
}

実行結果

デバイスコンテキストの色ビット数 = 32






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。