Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 PtInRegion pixel function


I am having trouble getting the Windows API function PtInRegion() to work correctly in Windows 3. and Windows 95 without generating an application error or GPF. What can I do to determine if a point is in a region reliably?   

    The Windows 3. and Windows 95 GDI heap is limited in regards to scan converting large and complex regions such as Ellipses, Polygons, and PolyPolygons. One "Brute Force" technique is to create an "in memory" monochrome bitmap and draw the required shape in black. You can then test to see if a given point in the bitmap is black or white. If the test pixel is black, then the given point is "in" the given region.

    Example:

    procedure TForm .Button Click(Sender: TObject); var bm : TBitmap; begin bm := TBitmap.Create; bm.Monochrome := true; bm.Height := 00; bm.Width := 00; bm.Canvas.Brush.Color := clWhite; bm.Canvas.FillRect(Rect(0, 0, 00, 00)); bm.Canvas.Brush.Color := clBlack; bm.Canvas.Pen.Color := clBlack; bm.Canvas.Ellipse( 0, 0, 90, 90); if bm.Canvas.Pixels[20, 20] = clBlack then ShowMessage('Point : (20, 20) is in region') else ShowMessage('Point : (20, 20) is not in region'); if bm.Canvas.Pixels[50, 50] = clBlack then ShowMessage('Point : (50, 50) is in region') else ShowMessage('Point : (50, 50) is not in region'); bm.Free; end; 7/ 6/98 4:3 :28 PM

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use