[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

how to create a brush with a transparent bitmap

I need to fill polygons with a certain pattern and a certain color. This is most easilly done with a patterned brush.
However the pattern must be transparent.( it must consist of one transparent part an one coloured part) It must work just  like a mask, but a mask only works on other bit arrays. What i need is more like another predefined hatchbrush.
These will work with any color, but i need a lot more patterns.  

It is possible to create a brush with CreatePatternBrush() (windows API), but with this method the background is affected.(NOT transparent)

In short: I need a way to create a brush with any pattern(not the predefined rubbish) and any color that must be partially transparent.

It must be a solution that will work with windows API calls only, not with OWL or something like that.
0
molli500
Asked:
molli500
1 Solution
 
molli500Author Commented:
Edited text of question
0
 
Tommy HuiCommented:
There isn't anything in Windows that knows about transparencies other than cursors and icons. You will need to write the code yourself if you want transparent brushes.
0
 
RONSLOWCommented:
Masks and bitmap operations are the best way to achieve this.

0
 
molli500Author Commented:
Masks and bitmap operations don't work with the predefined draw functions. That is why I need a brush. I can very probably program my way around this by using masks and such, but thta is what i am trying to avoid. One answer suggested this, but that wasn't the question. What I need is a brush that will not affect the background except where its pattern is. It should be possible to use any colour for any pattern.
0
 
SprocketCommented:
HDC hdc = GetDC(m_hWnd);

if (hdc)
{
long x=0, y=0, width=0, height=0;
            
            if (m_HorzDrag.size())
            {
                  HBRUSH hOld = (HBRUSH)SelectObject(hdc, m_hBrush);

                  x = m_recHDrag.left;
                  y = m_recHDrag.top;
                  width  = m_recHDrag.right -x;
                  height = m_recHDrag.bottom-y;

                  PatBlt(hdc, x, y, width, height, PATINVERT);
                  SelectObject(hdc, hOld);
            }
            if (m_VertDrag.size())
            {
                  HBRUSH hOld = (HBRUSH)SelectObject(hdc, m_hBrush);

                  x = m_recVDrag.left;
                  y = m_recVDrag.top;
                  width  = m_recVDrag.right -x;
                  height = m_recVDrag.bottom-y;

                  PatBlt(hdc, x, y, width, height, PATINVERT);
                  SelectObject(hdc, hOld);
            }

            ReleaseDC(m_hWnd, hdc);
      }
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now