how to create a brush with a transparent bitmap

Posted on 1997-11-20
Medium Priority
Last Modified: 2013-12-03
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.
Question by:molli500
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 1408639
Edited text of question
LVL 15

Expert Comment

by:Tommy Hui
ID: 1408640
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.
LVL 10

Expert Comment

ID: 1408641
Masks and bitmap operations are the best way to achieve this.


Author Comment

ID: 1408642
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.

Accepted Solution

Sprocket earned 1050 total points
ID: 1408643
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);

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question