// -- 時計針の回転 ダブルバッファリングを使った画像表示 --
int CClockWin2View::drawRotaionForBMP(CDC *pDC,
const GamePoint& drawPoint,
const double angleInDegree,
CImage *pimage
)
{
int width, height;
//画像の縦幅、横幅を取得します
width = pimage->GetWidth();
height = pimage->GetHeight();
HDC hDC = pimage->GetDC();
//透過マスクビットマップ
//ビットマップ本体
HBITMAP hBitmap2 = *pimage;
HDC hBitmapDC2 = hDC;
//透過マスクビットマップ
HBITMAP maskHBitmap2;
HDC maskBitmapDC2 = CreateCompatibleDC(NULL);
COLORREF oldBkColor = SetBkColor(hBitmapDC2,TRANSPARENT_COLOR);
maskHBitmap2 = CreateBitmap(
width, height,
1, 1,
NULL);
SelectObject( maskBitmapDC2, maskHBitmap2);
BitBlt(
maskBitmapDC2,
0, 0,
width, height,
hBitmapDC2,
0, 0,
NOTSRCCOPY//色反転
);
SetBkColor(hBitmapDC2, oldBkColor);
// --- --- ---
//画像の中心座標
GamePoint centerPoint(pimage->GetWidth() / 2, pimage->GetHeight() / 2);
//元画像の左上座標
GamePoint leftHighPoint(0, 0);
//元画像の右上座標
GamePoint rightHighPoint(pimage->GetWidth(), 0);
//元画像の左下座標
GamePoint leftLowPoint(0, pimage->GetHeight());
//座標を回転
leftHighPoint.rotate(angleInDegree, centerPoint);
rightHighPoint.rotate(angleInDegree, centerPoint);
leftLowPoint.rotate(angleInDegree, centerPoint);
//PlgBlt用 描画座標
//平行四辺形の[0]左上隅,[1]右上隅,[2]左下隅の座標
POINT point[3];
point[0].x = leftHighPoint.getXint() + drawPoint.getXint();
point[0].y = leftHighPoint.getYint() + drawPoint.getYint();
point[1].x = rightHighPoint.getXint() + drawPoint.getXint();
point[1].y = rightHighPoint.getYint() + drawPoint.getYint();
point[2].x = leftLowPoint.getXint() + drawPoint.getXint();
point[2].y = leftLowPoint.getYint() + drawPoint.getYint();
// --- CImageの回転処理 ---
pimage->PlgBlt(
pDC->GetSafeHdc(),
point, // 転送先平行四辺形の頂点
maskHBitmap2 //マスクビットマップ
);
//使用した仮想デバイスコンテキストのビットマップを廃棄します。
//(廃棄のタイミングはやりたいことの内容によって変わると思います。)
DeleteObject(maskHBitmap2);
pimage->ReleaseDC();//必ず開放する事!
return 0;
}