晕了~请问BitBlt里用SRCINVERT等参数时与前景色,背景色什么关系啊

crescendo 2004-05-10 07:58:48
比如有
CDC* pDC;
CBrush NewBrush;
CBrush *pOldBrush;
CRect rc;
GetClientRect(&rc);
COLORREF BackColor=RGB(0,0,0);
NewBrush.CreateSolidBrush(BackColor);
pOldBrush=pDC->SelectObject(&NewBrush);
pDC->FillRect(rc,&NewBrush);
NewBrush.DeleteObject();
pDC->SelectObject(pOldBrush);

然后用pDC指定了前景色和背景色,
pDC->SetBkColor(RGB(255,255,255));
pDC->SetTextColor(RGB(0,0,0));
后面有
pDC->BitBlt(50,50, nWidth, nHeight, &dcImage, 0, 0, SRCINVERT);
dcImage里的图是白色矩形里有一个绿色的三角
请问这个是怎样处理的啊?什么和什么XOR运算?和前景色,背景色什么关系啊

把SRCINVERT改成SRCAND又怎样呢?
...全文
434 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜牛 2004-05-12
  • 打赏
  • 举报
回复
建议你不要老是用白色、黑色来试验,太特殊了。改用其它颜色试试就知道了。
菜牛 2004-05-12
  • 打赏
  • 举报
回复

Windows GDI

BitBlt

The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

BOOL BitBlt(
HDC hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
DWORD dwRop // raster operation code
);
Parameters
hdcDest
[in] Handle to the destination device context.
nXDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidth
[in] Specifies the width, in logical units, of the source and destination rectangles.
nHeight
[in] Specifies the height, in logical units, of the source and the destination rectangles.
hdcSrc
[in] Handle to the source device context.
nXSrc
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYSrc
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
dwRop
[in] Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color.
The following list shows some common raster operation codes.

Value Description
BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
CAPTUREBLT Windows 98/Me, Windows 2000/XP: Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window. Note that this generally cannot be used for printing device contexts.
DSTINVERT Inverts the destination rectangle.
MERGECOPY Merges the colors of the source rectangle with the brush currently selected in hdcDest, by using the Boolean AND operator.
MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
NOMIRRORBITMAP Windows 98/Me, Windows 2000/XP: Prevents the bitmap from being mirrored.
NOTSRCCOPY Copies the inverted source rectangle to the destination.
NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
PATCOPY Copies the brush currently selected in hdcDest, into the destination bitmap.
PATINVERT Combines the colors of the brush currently selected in hdcDest, with the colors of the destination rectangle by using the Boolean XOR operator.
PATPAINT Combines the colors of the brush currently selected in hdcDest, with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator.
SRCCOPY Copies the source rectangle directly to the destination rectangle.
SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator.
WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks
BitBlt only does clipping on the destination DC.

If a rotation or shear transformation is in effect in the source device context, BitBlt returns an error. If other transformations exist in the source device context (and a matching transformation is not in effect in the destination device context), the rectangle in the destination device context is stretched, compressed, or rotated, as necessary.

If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color format to match the destination format.

When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context.

Not all devices support the BitBlt function. For more information, see the RC_BITBLT raster capability entry in the GetDeviceCaps function as well as the following functions: MaskBlt, PlgBlt, and StretchBlt.

BitBlt returns an error if the source and destination device contexts represent different devices. To transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to the second device, call SetDIBits or StretchDIBits.

ICM: No color management is performed when blits occur.

Example Code
For an example, see Capturing an Image.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
shoogun 2004-05-12
  • 打赏
  • 举报
回复
我也想知道 BitBlt和选中的画刷有什么关系?
crescendo 2004-05-11
  • 打赏
  • 举报
回复
我总算有点明白了。两位说的都是部分对。

Mackz(在相互) :BitBlt并非与前景色、背景色全无关系。
在用BitBlt将单色位图块传送到彩色DC上时,它就会把0位转换为目标DC的当前前景色(CDC::SetTextColor),将1位转换为目标设备描述表的当前背景颜色(CDC::SetBkColor)。
反过来,将彩色位图块传送到单色DC上时,BitBlt会把与目标设备描述表背景颜色匹配的象素转换为1而将所有其他象素转换为0。
如果全是彩色DC的话一般就与前景色,背景色没什么关系了。

不知道我这么说你们是否觉得正确。

正如code8238(二进制动物)的说法,我上面的程序是在黑色背景下显示了IDB_BITMAP1 (白色矩形里有一个绿色的三角)。
菜牛 2004-05-11
  • 打赏
  • 举报
回复
请看MSDN里的说明,什么前景色、背景色,只与文字绘制有关系,BitBlt有关的是目标DC的颜色、源DC的颜色、选中的画刷。
code8238 2004-05-11
  • 打赏
  • 举报
回复
应该是与前景色没关的,因为前景色只在彩色位图向单色设备转换时才起作用。
把底色设为RGB(0,0,0)(黑色),就是为了使图片能够原样显示,因为任何数和0异或都不变。如果是SRCAND的话,你将看到一个黑色的屏幕,因为任何数和0与都得0
crescendo 2004-05-10
  • 打赏
  • 举报
回复
dcImage如下:
CDC dcImage;
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
dcImage.CreateCompatibleDC(pDC);
CBitmap* pOldBitmapImage=dcImage.SelectObject(&bmp);

IDB_BITMAP1 是白色矩形里有一个绿色的三角
与前景色没关吗?而且前面已经在pDC上将客户区窗口都涂成黑色了,又有背景色,XOR怎么办?
crescendo 2004-05-10
  • 打赏
  • 举报
回复
没有人知道吗?请高手指教!
code8238 2004-05-10
  • 打赏
  • 举报
回复
dcImage你没说是什么啊!
XOR就是这个dcImage的像素值和底色的象素值进行XOR运算

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧