下面C++代码如何转为delphi代码啊。 ( 积分: 20 )

  • 主题发起人 主题发起人 ycguser
  • 开始时间 开始时间
Y

ycguser

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,下面代码如何转化成delphi代码。分不多了,以后在加
static void PrepareMask( HBITMAP bmpSource,
HBITMAP &bmpMask,
COLORREF clrpTransColor, // Pass null if unknown
int iTransPixelX = 0, // = 0
int iTransPixelY = 0 // = 0
)
{
BITMAP bm;

// Get the dimensions of the source bitmap
ATLVERIFY(::GetObject(bmpSource, sizeof(BITMAP), &bm));

// Create the mask bitmap
if(bmpMask) ::DeleteObject(bmpMask);
ATLVERIFY(bmpMask = ::CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL));

// We will need two DCs to work with. One to hold the Image
// (the source), and one to hold the mask (destination).
// When blitting onto a monochrome bitmap from a color, pixels
// in the source color bitmap that are equal to the background
// color are blitted as white. All the remaining pixels are
// blitted as black.

WTL::CDC hdcSrc, hdcDst;

ATLVERIFY(hdcSrc.CreateCompatibleDC(NULL));
ATLVERIFY(hdcDst.CreateCompatibleDC(NULL));

// Load the bitmaps into memory DC
HBITMAP hbmSrcT = hdcSrc.SelectBitmap(bmpSource);
HBITMAP hbmDstT = hdcDst.SelectBitmap(bmpMask);

// Dynamically get the transparent color
COLORREF clrTrans;
if (clrpTransColor == NULL)
{
// User did not specify trans color so get it from bmp
clrTrans = hdcSrc.GetPixel(iTransPixelX, iTransPixelY);
}
else
{
clrTrans = clrpTransColor;
}

// Change the background to trans color
COLORREF clrSaveBk = hdcSrc.SetBkColor(clrTrans);

// This call sets up the mask bitmap.
ATLVERIFY(hdcDst.BitBlt(0,0,bm.bmWidth, bm.bmHeight, hdcSrc,0,0,SRCCOPY));

COLORREF clrSaveDstText = hdcSrc.SetTextColor(RGB(255,255,255));
hdcSrc.SetBkColor(RGB(0,0,0));

ATLVERIFY(hdcSrc.BitBlt(0,0,bm.bmWidth, bm.bmHeight, hdcDst,0,0,SRCAND));

// Clean up by deselecting any objects, and delete the
// DC's.
hdcDst.SetTextColor(clrSaveDstText);

hdcSrc.SetBkColor(clrSaveBk);
hdcSrc.SelectBitmap(hbmSrcT);
hdcDst.SelectBitmap(hbmDstT);

hdcSrc.DeleteDC();
hdcDst.DeleteDC();
}



static BOOL TransparenceDrawing(HDC hdcTarget, const int x, const int y, const int nWidth, const int nHeight,
const int xSrc, const int ySrc, const int nSrcWidth, const int nSrcHeight,
HDC dcMask, HDC dcBitmap)
{
BOOL bRet = TRUE;

// prevent affected
COLORREF oldTextClr = ::SetTextColor(hdcTarget, RGB(0,0,0));
COLORREF oldBackClr = ::SetBkColor(hdcTarget, RGB(255,255,255));

if(nWidth == nSrcWidth &&amp
nHeight == nSrcHeight)
bRet = ::BitBlt(hdcTarget, x, y, nWidth, nHeight, dcMask, xSrc, ySrc, SRCAND);
else
bRet = ::StretchBlt(hdcTarget, x, y, nWidth, nHeight, dcMask, xSrc, ySrc, nSrcWidth, nSrcHeight, SRCAND);

::SetTextColor(hdcTarget, oldTextClr);
::SetBkColor(hdcTarget, oldBackClr);

if(bRet)
{
if(nWidth == nSrcWidth &&amp
nHeight == nSrcHeight)
bRet = ::BitBlt(hdcTarget, x, y, nWidth, nHeight, dcBitmap, xSrc, ySrc, SRCPAINT);
else
bRet = ::StretchBlt(hdcTarget, x, y, nWidth, nHeight, dcBitmap, xSrc, ySrc, nSrcWidth, nSrcHeight, SRCPAINT);
}

return bRet;
}
 
各位高手,下面代码如何转化成delphi代码。分不多了,以后在加
static void PrepareMask( HBITMAP bmpSource,
HBITMAP &bmpMask,
COLORREF clrpTransColor, // Pass null if unknown
int iTransPixelX = 0, // = 0
int iTransPixelY = 0 // = 0
)
{
BITMAP bm;

// Get the dimensions of the source bitmap
ATLVERIFY(::GetObject(bmpSource, sizeof(BITMAP), &bm));

// Create the mask bitmap
if(bmpMask) ::DeleteObject(bmpMask);
ATLVERIFY(bmpMask = ::CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL));

// We will need two DCs to work with. One to hold the Image
// (the source), and one to hold the mask (destination).
// When blitting onto a monochrome bitmap from a color, pixels
// in the source color bitmap that are equal to the background
// color are blitted as white. All the remaining pixels are
// blitted as black.

WTL::CDC hdcSrc, hdcDst;

ATLVERIFY(hdcSrc.CreateCompatibleDC(NULL));
ATLVERIFY(hdcDst.CreateCompatibleDC(NULL));

// Load the bitmaps into memory DC
HBITMAP hbmSrcT = hdcSrc.SelectBitmap(bmpSource);
HBITMAP hbmDstT = hdcDst.SelectBitmap(bmpMask);

// Dynamically get the transparent color
COLORREF clrTrans;
if (clrpTransColor == NULL)
{
// User did not specify trans color so get it from bmp
clrTrans = hdcSrc.GetPixel(iTransPixelX, iTransPixelY);
}
else
{
clrTrans = clrpTransColor;
}

// Change the background to trans color
COLORREF clrSaveBk = hdcSrc.SetBkColor(clrTrans);

// This call sets up the mask bitmap.
ATLVERIFY(hdcDst.BitBlt(0,0,bm.bmWidth, bm.bmHeight, hdcSrc,0,0,SRCCOPY));

COLORREF clrSaveDstText = hdcSrc.SetTextColor(RGB(255,255,255));
hdcSrc.SetBkColor(RGB(0,0,0));

ATLVERIFY(hdcSrc.BitBlt(0,0,bm.bmWidth, bm.bmHeight, hdcDst,0,0,SRCAND));

// Clean up by deselecting any objects, and delete the
// DC's.
hdcDst.SetTextColor(clrSaveDstText);

hdcSrc.SetBkColor(clrSaveBk);
hdcSrc.SelectBitmap(hbmSrcT);
hdcDst.SelectBitmap(hbmDstT);

hdcSrc.DeleteDC();
hdcDst.DeleteDC();
}



static BOOL TransparenceDrawing(HDC hdcTarget, const int x, const int y, const int nWidth, const int nHeight,
const int xSrc, const int ySrc, const int nSrcWidth, const int nSrcHeight,
HDC dcMask, HDC dcBitmap)
{
BOOL bRet = TRUE;

// prevent affected
COLORREF oldTextClr = ::SetTextColor(hdcTarget, RGB(0,0,0));
COLORREF oldBackClr = ::SetBkColor(hdcTarget, RGB(255,255,255));

if(nWidth == nSrcWidth &&amp
nHeight == nSrcHeight)
bRet = ::BitBlt(hdcTarget, x, y, nWidth, nHeight, dcMask, xSrc, ySrc, SRCAND);
else
bRet = ::StretchBlt(hdcTarget, x, y, nWidth, nHeight, dcMask, xSrc, ySrc, nSrcWidth, nSrcHeight, SRCAND);

::SetTextColor(hdcTarget, oldTextClr);
::SetBkColor(hdcTarget, oldBackClr);

if(bRet)
{
if(nWidth == nSrcWidth &&amp
nHeight == nSrcHeight)
bRet = ::BitBlt(hdcTarget, x, y, nWidth, nHeight, dcBitmap, xSrc, ySrc, SRCPAINT);
else
bRet = ::StretchBlt(hdcTarget, x, y, nWidth, nHeight, dcBitmap, xSrc, ySrc, nSrcWidth, nSrcHeight, SRCPAINT);
}

return bRet;
}
 
后退
顶部