PDA

Click to See Complete Forum and Search --> : calculate area or number of pixels in a filled area


littleenoch
Aug 24th, 2000, 12:09 PM
I need an api call that will calculate the area of a shape that has been drawn on the screen. It is for use on a program to figurine square feet of a house. The user draws the outline of the house, we fill the drawing with a fill tool, then I need to determine the area of the filled space on the screen.

There has to be something that converts pixels to inches or feet or something. I just need some way of finding out how many pixels are in a filled area.

Please, if you have any suggestions, please let me know.

clint

hypnos
Aug 24th, 2000, 12:17 PM
1 inche = 72 pixels
72 pixels = 2.54 cm

littleenoch
Aug 24th, 2000, 12:21 PM
How do I get Windows to tell me how many pixels have been changed so I can figure the area?

thanks,

clint

hypnos
Aug 24th, 2000, 12:40 PM
Sorry littleenoch, I don't understand the second question, please give me a little more info on what you want to do. Thanks

littleenoch
Aug 24th, 2000, 12:50 PM
First of all, let me thank you for looking and responding to my questions.

I have a program that will draw an area on the screen changing the background pixels to blue. I want to know how many pixels have been changed to blue so I can calculate the area of my drawing.

Example: I draw a filled box on the screen with my draw tool. All of the pixels in the box turn blue (or whatever color I chose). Now, I need to know how many pixels I just colored blue. I need an API call that tells me how many pixels I just turned blue so I can calculate the area of the box I just drew.

I hope that makes sense. and again, thanks for your help.

clnt

Aug 24th, 2000, 01:10 PM
Why not just loop through the area of the box and increment a variable when it's blue

Dim iCount As Integer

For X = 0 To BoxWidth
For Y = 0 To BoxHeight
pColor = GetPixel(Box.hDC, X, Y)
If pColor = vbBlue Then iCount = iCount + 1
Next Y
Next X

MsgBox "There were " & iCount & " blue pixels in total"

Mad Compie
Aug 24th, 2000, 01:31 PM
There is a book that explains graphics algorithms, like Bresenham's algorithms for drawing lines and circles.
There were also algorithms to fill areas defined by colour. If you can fill them, you can also de-fill them.
It's an old book (in DOS times!) but very handy!
Only 1 problem: what book was that?
I thought the title was "Graphics Programming in C".
It also explains some graphics structures to save drawings to files.

hypnos
Aug 24th, 2000, 01:54 PM
Providing that there will be no more pixels if the colour blue then Megatron's way will work fine.

IrishJoker
Aug 28th, 2000, 10:59 AM
Hi

I would think that when you are drawing the box,
you would be using a mouse.

If so, why don't you get the position where the user
clicked and released the mouse button. You coul calculate
the size of all the sides and teh area of the box this way.

Hope this is of some help...

IJ