Solved

Region from Bitmap (Win32)

Posted on 1998-02-11
5
606 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 200 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to DocumentFormat 8 126
Windows Process running 3 62
Need to impress with my knowledge of .NET 5 100
reboot server with scheduled time and week base 4 65
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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