画面画像をキャプチャしてPNG形式で保存.そのときに,boost::gilを使用した例.
/// 画面をキャプチャする
void CPY_CaptureScreen(const std::wstring &szFilePath) {
auto pDlg = GetMainDlg(); // 窓(CWnd*)を得る
CRect rectClient;
pDlg->GetClientRect( &rectClient );
CClientDC dc(pDlg);
CDC dc2;
dc2.CreateCompatibleDC( &dc );
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height() );
auto pOldBitmap = dc2.SelectObject( &bitmap );
dc2.BitBlt(0,0, rectClient.Width(), rectClient.Height(), &dc, 0, 0, SRCCOPY );
int nWidthAdjust = rectClient.Width();
if ( nWidthAdjust % 4 ) { nWidthAdjust += 4 - nWidthAdjust % 4;}
std::vector<BYTE> bitdata( nWidthAdjust * rectClient.Height() * 3 );
dc2.SelectObject( pOldBitmap );
BITMAPINFO bitmapinfo;
ZeroMemory(&bitmapinfo, sizeof(BITMAPINFO) );
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biWidth = nWidthAdjust;
bitmapinfo.bmiHeader.biHeight = rectClient.Height();
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biBitCount = 24;
bitmapinfo.bmiHeader.biCompression = BI_RGB;
GetDIBits( dc2, bitmap, 0, rectClient.Height(), bitdata.data(), &bitmapinfo, DIB_RGB_COLORS );
boost::gil::rgb8_image_t img( nWidthAdjust, rectClient.Height() );
copy_pixels(boost::gil::interleaved_view(nWidthAdjust, rectClient.Height(), (const boost::gil::rgb8_pixel_t*)bitdata.data(), nWidthAdjust*3), view(img));
png_write_view(CStringA(szFilePath.c_str()), boost::gil::flipped_up_down_view( const_view(img) ) );