Solved

Region from Bitmap (Win32)

Posted on 1998-02-11
5
597 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now