 |
操作系统: windowsXP
编程工具: vc++
问题:
BitBlt(hDC,SKBD_SHX + 1,SKBD_N4 + 1,SKBD_SHCX,24,hMemDC,1115 + SKBD_TABCX * 5 + SKBD_CLCX + SKBD_ENCX,0,SRCCOPY);对加载的图片怎么放大一倍????
水平: 中级(whoopee)
|
| |
|
 |
BitBlt只能进行原始大小的复制,而不能进行缩小和放大的操作。要进行缩放,需要使用StretchBlt函数:
BOOL StretchBlt(
HDC hdcDest, // 目标设备环境句柄
int nXOriginDest, // 目标矩形的坐标原点
int nYOriginDest,
int nWidthDest, // 目标矩形的长度和宽度
int nHeightDest,
HDC hdcSrc, // 源设备环境句柄
int nXOriginSrc, // 源矩形的坐标原点
int nYOriginSrc,
int nWidthSrc, // 源矩形的长度和宽度
int nHeightSrc,
DWORD dwRop // 光栅操作标志
);
同BitBlt相比,多出两个参数,就是目标矩形的长度和宽度,你可以通过合理地设置这两个参数来取得缩放效果。
下面是一个例子:
hdcScaled = CreateCompatibleDC(hdcScreen);
hbmScaled = CreateCompatibleBitmap(hdcScreen,
GetDeviceCaps(hdcScreen, HORZRES) * 2,
GetDeviceCaps(hdcScreen, VERTRES) * 2);
if (hbmScaled == 0)
errhandler("hbmScaled", hwnd);
// Select the bitmaps into the compatible DC.
if (!SelectObject(hdcScaled, hbmScaled))
errhandler("Scaled Bitmap Selection", hwnd);
case WM_COMMAND: // message: command from application menu
switch(wParam)
{
case IDM_SCALEX1:
if (fBlt)
{
fScaled = FALSE;
hdcWin = GetDC(hwnd);
BitBlt(hdcWin,
0,0,
bmp.bmWidth, bmp.bmHeight,
hdcCompatible,
0,0,
SRCCOPY);
ReleaseDC(hwnd, hdcWin);
}
break;
case IDM_SCALEX2:
if (fBlt)
{
fScaled = TRUE;
StretchBlt(hdcScaled,
0, 0,
bmp.bmWidth * 2, bmp.bmHeight * 2,
hdcCompatible,
0, 0,
bmp.bmWidth, bmp.bmHeight,
SRCCOPY);
hdcWin = GetDC(hwnd);
BitBlt(hdcWin,
0,0,
bmp.bmWidth, bmp.bmHeight,
hdcScaled,
0,0,
SRCCOPY);
ReleaseDC(hwnd, hdcWin);
}
break;
此问题由李海回答。
附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, 图形、图象, picture, graph, image, draw。
|
| |
|
| |
|
| |
|
|