Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Region from Bitmap (Win32)

Posted on 1998-02-11
Medium Priority
619 Views
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.
0
Question by:greendot
[X]
###### 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
• 2
• 2

LVL 1

Expert Comment

ID: 1411179
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

0

LVL 2

Author Comment

ID: 1411180
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.  :)

Thanks!
0

LVL 22

Accepted Solution

nietod earned 800 total points
ID: 1411181
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!
0

LVL 1

Expert Comment

ID: 1411182
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.....
0

LVL 22

Expert Comment

ID: 1411183
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.
0

## Featured Post

Question has a verified solution.

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