Region from Bitmap (Win32)

Is there any way to define a region from a monochrome bitmap?

I've gone thru and pixel by pixel, created and then combined tiny 1-pixel regions but that takes forever to complete.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In my programms I must created non retangular window by monochrome bitmap. In WINAPI I din't find any function. There are not them. You have 2 basic ways to do it.

1. Calkul polypolygon points and call CreatePolyRegion. Hehe... If you'll do it, WINDOWS plot region away some points :(((
(bug or what ? But this is fact, I tryed it.....)

2. Better way, very simple. We have bitmap (200x300). You must craete region 1 (200x300 which will be filled) , region 2 (2x2 pixel filled). Not you must to check all pixels in bitmap:
  for (int x=0;x<200;x++)
    for (int y=0;y<300;y++)
     if (BitmapPixel(x,y) is SET)
        CombieRegion(r1,r2,...,XOR methode)

the last step is to XOR region.... I thing that it is the simples way.... You can save region data to disk and next time load it. But have in mind, that windows combine region ONLY WHEN the HEIGHT is more then 2 pixels.... If the height is 1 pixel, the will ignore it. If you are in C, I can send you full source of this procedure - 30 lines :) . If you'll try OR methode, you will have problems.... That caused i used XOR...

I thing this is all..... If you have question, write them :)

              yours Ray/Unreal

ps:sorry for bad english....
greendotAuthor Commented:
How do you save a region to disk?

I've tried both of these methods already.  The only one that works for me is the CombineRgn().  My only problem with that is the time it takes to combine all the 2x2 regions.  It takes a very long time.

Saving it to disk would work fine for me.  :)

To save the region informaiton to disk, you can use GetRegionData to get the region data and then save the region data yourself.  To recreate the region load the data and use ExtCreateRegion()

To create the region I would create a polygon that bounds the bitmap with the minimum number of points needed.  Then use CreatePolyRgn().  This should be much faster than creating a region using every point!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you use CreatePoltRgn(), some pixels aorund wiln't be "filled", caused by bug in WINAPI. Belive me, i tryed it with big regions (about 200 points). Next problem is to calculate them. Pixel per pixel and load/save is fatster.....
I've nevery used CreatePolyRgn in complex enough cases to see a bug.  However, I suspect this is not a bug.  Windows often does not include the bottom and right edges of an abject in a drawing operation.  If you fill a rectangle the last row of pixels on the bottom and right edges are not touched.  This is not a bug, this is intentional.  A retangular region with the coordinates (0,0,1,1) will probably not draw anything.   A rectangular region (0,0,2,2) will probably draw one pixel.  You make need to adjust your polygon points to take this into account.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.