本文整理汇总了C++中gfx::Canvas::DrawMaskedBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ Canvas::DrawMaskedBitmap方法的具体用法?C++ Canvas::DrawMaskedBitmap怎么用?C++ Canvas::DrawMaskedBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gfx::Canvas
的用法示例。
在下文中一共展示了Canvas::DrawMaskedBitmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
/*
** Draws the meter on the double buffer
**
*/
bool MeterImage::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
if (m_Image.IsLoaded())
{
// Copy the image over the doublebuffer
Bitmap* drawBitmap = m_Image.GetImage();
int imageW = drawBitmap->GetWidth();
int imageH = drawBitmap->GetHeight();
if (imageW == 0 || imageH == 0 || m_W == 0 || m_H == 0) return true;
Gdiplus::Rect meterRect = GetMeterRectPadding();
int drawW = meterRect.Width;
int drawH = meterRect.Height;
bool hasMask = (m_Skin->GetUseD2D() && m_MaskImage.IsLoaded());
if (hasMask)
{
Bitmap* maskBitmap = m_MaskImage.GetImage();
imageW = maskBitmap->GetWidth();
imageH = maskBitmap->GetHeight();
int imageMW = drawBitmap->GetWidth();
int imageMH = drawBitmap->GetHeight();
int cropX = 0;
int cropY = 0;
int cropW = imageMW;
int cropH = imageMH;
REAL imageratio = imageMW / (REAL)imageMH;
REAL meterRatio = meterRect.Width / (REAL)meterRect.Height;
if (imageratio != meterRatio)
{
if (imageratio > meterRatio)
{
cropW = (int)(imageMH * meterRatio);
cropX = (imageMW - cropW) / 2;
}
else
{
cropH = (int)(imageMW / meterRatio);
cropY = (imageMH - cropH) / 2;
}
}
canvas.DrawMaskedBitmap(drawBitmap, maskBitmap, meterRect, Rect(0, 0, imageW, imageH), Gdiplus::Rect(cropX, cropY, cropW, cropH));
}
else if (drawW == imageW && drawH == imageH &&
m_ScaleMargins.left == 0 && m_ScaleMargins.top == 0 && m_ScaleMargins.right == 0 && m_ScaleMargins.bottom == 0)
{
canvas.DrawBitmap(drawBitmap, Rect(meterRect.X, meterRect.Y, drawW, drawH), Rect(0, 0, imageW, imageH));
}
else if (m_DrawMode == DRAWMODE_TILE)
{
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
ImageAttributes imgAttr;
imgAttr.SetWrapMode(WrapModeTile);
Rect r(meterRect.X, meterRect.Y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr);
canvas.EndGdiplusContext();
}
else if (m_DrawMode == DRAWMODE_KEEPRATIO || m_DrawMode == DRAWMODE_KEEPRATIOANDCROP)
{
int cropX = 0;
int cropY = 0;
int cropW = imageW;
int cropH = imageH;
if (m_WDefined && m_HDefined)
{
REAL imageRatio = imageW / (REAL)imageH;
REAL meterRatio = meterRect.Width / (REAL)meterRect.Height;
if (imageRatio != meterRatio)
{
if (m_DrawMode == DRAWMODE_KEEPRATIO)
{
if (imageRatio > meterRatio)
{
drawH = meterRect.Width * imageH / imageW;
meterRect.Y += (meterRect.Height - drawH) / 2;
}
else
{
drawW = meterRect.Height * imageW / imageH;
meterRect.X += (meterRect.Width - drawW) / 2;
//.........这里部分代码省略.........