?
Solved

Region from Bitmap (Win32)

Posted on 1998-02-11
5
Medium Priority
?
614 Views
Last Modified: 2013-12-03
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:rayofunreal
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

ps:sorry for bad english....
0
 
LVL 2

Author Comment

by:greendot
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

by:
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

by:rayofunreal
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

by:nietod
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

771 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