如何使用PNG图像创建图案画笔。 [英] How to create pattern brush using PNG image.
问题描述
我在白色背景中有黑点的图像,我用它来创建一个模板画笔并使用SetTextColor更改黑点的颜色。我使用PNG图像创建了一个CBitmap(我使用CPngImage获取HBITMAP并将其附加到CBitmap)。现在我使用(CreatePatternBrush)使用该位图创建了PatternBrush,问题是如果我使用PNG图像,画笔的颜色不会改变。但是当我使用bmp格式的图像时它会改变。
我尝试过的事情:
这里是一些代码
CBitmap bmp;
if(bmp.LoadBitmap(IDB_BITMAP1))
{
if(brush.CreatePatternBrush(& bmp))
pOldBrush = pDC-> SelectObject(& brush);
}
pDC-> SetTextColor(color);这个作品
CBitmap bmp;
CPngImage pngImage;
HBITMAP hBitmap = NULL;
if(pngImage.Load(MAKEINTRESOURCE(nIDResource)))
{
hBitmap =(HBITMAP)pngImage.Detach() ;
}
if(hBitmap)
bmp.Attach( hBitmap);
if(brush.CreatePatternBrush(& bmp))
pOldBrush = pDC-> SelectObject(& brush) ;
pDC-> SetTextColor(color);这不起作用
I have image with black dots in a white background, which i use to create a patten brush and change the color of the black dots using SetTextColor. I created a CBitmap using PNG image(i used CPngImage to get HBITMAP and attached it to CBitmap ). Now i created PatternBrush using(CreatePatternBrush) with that bitmap, the problem is that the color of the brush doesn't change if i use PNG image. But it changes when i use image in bmp format.
What I have tried:
here is some code
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
if (brush.CreatePatternBrush(&bmp))
pOldBrush = pDC->SelectObject(&brush);
}
pDC->SetTextColor(color); This Works
CBitmap bmp;
CPngImage pngImage;
HBITMAP hBitmap = NULL;
if ( pngImage.Load(MAKEINTRESOURCE(nIDResource)) )
{
hBitmap = (HBITMAP)pngImage.Detach();
}
if ( hBitmap )
bmp.Attach(hBitmap);
if (brush.CreatePatternBrush(&bmp))
pOldBrush = pDC->SelectObject(&brush);
pDC->SetTextColor(color); This Doesn't work
推荐答案
看起来你的位图IDB_BITMAP1
是单色而你的PNG图像不是。
It looks like your bitmapIDB_BITMAP1
is monochrome while your PNG image is not.
使用当前文本和背景颜色绘制使用单色位图(1个颜色平面,每像素1位)创建的画笔。由位设置为0表示的像素用当前文本颜色绘制。由位设置为1表示的像素用当前背景颜色绘制。
A brush created using a monochrome bitmap (1 color plane, 1 bit per pixel) is drawn using the current text and background colors. Pixels represented by a bit set to 0 are drawn with the current text color. Pixels represented by a bit set to 1 are drawn with the current background color.
因此由 SetTextColor
和 SetBkColor $设置的颜色c $ c>用于从单色位图创建的画笔。但是,使用非单色位图创建的画笔,会使用位图中的颜色。如果您不需要具有多种颜色的画笔并想要使用PNG图像,请将其转换为单色。
So the colours set by SetTextColor
and SetBkColor
are used with brushes created from monochrome bitmaps. But with brushes created from non-monochrome bitmaps, the colours from the bitmap are used. If you don't need brushes with multiple colours and want to use a PNG image, convert that to monochrome.
这篇关于如何使用PNG图像创建图案画笔。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!