Results 1 to 8 of 8

Thread: Copy a image by color...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Location
    sweden
    Posts
    176

    Copy a image by color...

    Hello again, i got 3-7 images in a picturebox and i need to copy each of those images by the outline color into a new picbox.

    how can i do this with the BitBlt?

    Thanks again!
    naitsabes

  2. #2
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787
    are they all the same size?

  3. #3
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    use get pixel/set pixel

    (lets pretend a pic within a pic is 10x10)
    loop from point 0,1 going left to right. (assuming 0-10,0 is the outline). Get each pixel as you loop

    check the color of each pixel, if it is not the outline color then set it in a new picture box.

    Once it hits the outline color, assuming you are going from right to left, just increment the y by 1....so then you will now get pixels on the next line.

    Continue this, until y=10.

    Now if all your pics are different sizes, then during the loop of get/set pixels you must find the width of the object, which is easy, endpoint-startpoint (end point would be when the getpixel gets an outline color pixel).

    Now if you ever have a line which each pixel in the width is the outline color you are at the bottom.

    I know code for this, but I did not feel like typing it and I cannot find any app's of mine which has this in use.

    So, if you are still confused post and I'll clarify.

    If you do not know Get/Set Pixel, check out the Window API calls.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Location
    sweden
    Posts
    176
    Hello, no im sorry to say that the pictures is not same size.
    Can you show me a example using start and stop-point?
    Big thanks,
    Naitsabes

  5. #5
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Could you post an example image, and an example of what you want copied? You may be able to do it using a method similar to the last problem you posted, but i don't quite understand what you want.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Location
    sweden
    Posts
    176
    Hello again, i posted a picture of my question at:
    http://hem.passagen.se/aiobot/myqv.JPG
    (I used 2 images in the picture, but max count = 11)

    First i must look at the main picture (picture1) for the red outline of each image, then copy the image into a new picturebox.

    Note that sometimes it can be a red line inside the picture too, not only the red outline

    Thanks,
    Naitsabes
    Last edited by naitsabes85; Sep 16th, 2004 at 11:30 AM.

  7. #7
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Since the pictures aren't one colour (as you say), you can't really use floodfill that effectivlly.

    Here is my proposed method:

    NOTE if there is never any red pixels within the image skip this

    Create a 2D boolean array the same size as the image - call this OutlineArr. This will be used to store pixels that are in the current image we're tracing around.

    We also need a way to keep track of our current direction as we trace round the outline of the image.
    Make an enumerated type 'Direction' with 4 values: Up, Down, Left and Right.

    Make a function that returns the next direction clockwise (called Rotate) to it's parameter. i.e, parameter Up returns Left, Left returns Down etc...

    I'll also assume you can make a function (or use directly) that returns true if the pixel passed in is red, otherwise false. I'm calling this function IsOutline.

    The thing i need is a function that returns the coordinates infront of the one's passed in (dependent on the direction parameter passed in).

    First locate an edge. Do this in the same way as before - looping top to bottom, left to right, with 2 nested for loops.

    Once you find a red pixel (an outline) do the following:

    Code:
    Direction = left
    while OutlineArr[Current.x,Current.y] = false do
        OutlineArr[CurrentX,CurrentY] = true
        while IsOutline[InFront(Current,Direction)] = false do
            direction = Rotate(direction)
        loop
        Current = InFront(current,Direction)
    loop


    This will mark all outline pixels for one image as true in the OutlineArr array.
    NOTE if you skipped to here loop through the image marking red pixels as true in the OutlineArr array.


    Next get a pixel in the image (one next to the first outline pixel we found (NOTE: check it's not an outline pixel it's self)).

    From this pixel right a recursive algorithm that marks it's pixel, then copies the pixel to a new image file and sets the pixel colour of the original image to non-red then calls its self for the pixels up, down, left and right (if unmarked and not true in OutlineArr).
    Finally loop through OutlineArr making the pixels non-red if outlineArr is true for them, and also set their value to false in the OutlineArr.

    You're now ready to do your 2nd image.
    Repeat until no red pixels are found in the original.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Location
    sweden
    Posts
    176
    Thanks SLH ill try the code tomorrow!
    naitsabes

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