//------------------------------------------------------------------------------
// $Workfile: ImageUtils.cpp $
// $Header: $
//
// Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
// Steve Johnson
//
// $Revision: $
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "ImageUtils.h"
#include "GDIUtils.h"
namespace SbjCore
{
namespace Utils
{
namespace Image
{
BmpRibbon::BmpRibbon()
{
}
BmpRibbon::~BmpRibbon()
{
}
int BmpRibbon::Create(UINT *pnIDArray, int nCount, CSize bmpSize,
COLORREF clrMask /*= RGB(255, 0, 255)*/, bool bCenterTooSmall /*= true*/)
{
int nRslt = 0;
CWindowDC dc(CWnd::GetDesktopWindow());
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CreateCompatibleBitmap(&dc, nCount * bmpSize.cx, bmpSize.cy);
Utils::GDI::Object<CBitmap> selectedBmp(&dcMem, this);
CBrush brush;
brush.CreateSolidBrush(clrMask);
Utils::GDI::Object<CBrush> selectedBrush(&dcMem, &brush);
dcMem.PatBlt(0, 0, nCount * bmpSize.cx, bmpSize.cy, PATCOPY);
for (int nIndex = 0; nIndex < nCount; nIndex++)
{
CDC dcSrc;
dcSrc.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.LoadBitmap(pnIDArray[nIndex]);
Utils::GDI::Object<CBitmap> selectedSrcBmp(&dcSrc, &bmp);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
int xOffset = 0;
int nWidth = bmpSize.cx;
if (bmpInfo.bmWidth < bmpSize.cx)
{
if (bCenterTooSmall)
{
xOffset = (bmpSize.cx - bmpInfo.bmWidth) / 2;
}
nWidth = bmpInfo.bmWidth;
}
int yOffset = 0;
int nHeight = bmpSize.cy;
if (bmpInfo.bmHeight < bmpSize.cy)
{
if (bCenterTooSmall)
{
yOffset = (bmpSize.cy - bmpInfo.bmHeight) / 2;
}
nHeight = bmpInfo.bmHeight;
}
dcMem.BitBlt((nIndex * bmpSize.cx) + xOffset, yOffset, nWidth, nHeight,
&dcSrc, 0, 0, SRCCOPY);
}
return nRslt;
}
}
}
}
//*** Modification History ***
// $Log: $