Results 1 to 9 of 9

Thread: calculate area or number of pixels in a filled area

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Twin Falls
    Posts
    5
    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

  2. #2
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    1 inche = 72 pixels
    72 pixels = 2.54 cm

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Twin Falls
    Posts
    5

    How do I get the number of pixels that have changed?

    How do I get Windows to tell me how many pixels have been changed so I can figure the area?

    thanks,

    clint

  4. #4
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    Sorry littleenoch, I don't understand the second question, please give me a little more info on what you want to do. Thanks

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Twin Falls
    Posts
    5

    Smile Thanks

    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

  6. #6
    Guest
    Why not just loop through the area of the box and increment a variable when it's blue
    Code:
    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"

  7. #7
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Red face

    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.

  8. #8
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Wink

    Providing that there will be no more pixels if the colour blue then Megatron's way will work fine.

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Location
    Ireland, Dublin
    Posts
    76

    Talking

    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
    ---------------------------------
    TopMan
    ---------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width