Results 1 to 7 of 7

Thread: Selection region on Transparent bitmap

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337

    Selection region on Transparent bitmap

    I'm looking for the answers to a coupld of questions about clicking on / selecting a transparent bitmap (or bitmaps!).

    I have StretchBlt'd my bitmap and mask to create on-the-fly transparencies with the top-left pixel defining the transparency.

    That is all fine.

    I want actions to occur when the user clicks on the bitmap.
    I can do this using the bounding rectangle, but I'd like to ignore the transparent regions (i.e. just react to clicks on the visible parts).

    I'd also like to 'highlight' the bitmap with a border OnMouseOver,
    again with a border around the visible regions.

    I suspect this involves the use of 'Regions' and masks and such, but I really don't know where to start?

    Does anyone?

    Thx,

    Dan

    Dan

    Outside of a dog, a book is a man's best friend.
    Inside of a dog, it's too dark to read.

  2. #2
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    well, you could just check to see if its in the rectangle of the bitmap, and then once you do that check to see if the color of the pixel you clicked was of the color of the object behind the bitmap. For instance, use:
    Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    blit the transparant bitmap to the form, then when you click, if the color is equal to the color of the form, you know you clicked the transparant part, or didn't click if its not the color. as far as the border, create a transparant bitmap that would serve as the border, and just blit over the bitmap when you mouseover it (you can check getpixel on mousemove too).
    hope that helps, i just thought of it.......

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337
    Thanks for the reply, I must admit that method (pixel colour)occured to me after posting, but I was wondering if there was a 'cleverer' way Also, it breaks down since I have no way of knowing what the pixel colour behind the bitmap is going to be (there could be other user defined shapes or bitmpas 'beneath' the one of interest).

    As for the border, I'd need something generic based on the bitmap itself, since the user can load any bitmap. I was thinking you might somehow be able to use the masked-source or the mask bitmap, since they essentially contain the outline of the shape of the bitmap.

    What I need to do then is programmatically trace around the outline, adding pixels of my highlight colour. Sounds difficult, but is it impossible?

    Dan

    Outside of a dog, a book is a man's best friend.
    Inside of a dog, it's too dark to read.

  4. #4
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    you want to create the outline dynamically? that would some algorithm.
    you could take the bitmap, shrink its mask, blit the mask over the source, but don't blit it at (0,0) on the source. figure out a factor, xoffset-yoffset so that what youre left with is the bitmap with a black center that is the same shape but smaller that the source bitmap. you then would have an outline that would be made of the color pixels from the source. you then could read that bitmap. if the background is white and the mask was black, you could find all the pixels that are color(the outline from the source), and put those pixels in a new bitmap as whatever color you want. This would be the outline. I know this must sound totally ridculous, but its an idea. it would require a large knowledge of GetBitmapBits and SetBitmapBits and creating dynamic(and empty) bitmaps and how the individual bits of a bitmap are setup, but i think its possible.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337

    Region solution?

    I found this:

    http://www.codeproject.com/gdi/coolrgn.asp

    which works for any bitmap. I might be able to adapt it,
    if I can figure out how it works!

    Dan

    Outside of a dog, a book is a man's best friend.
    Inside of a dog, it's too dark to read.

  6. #6
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    yeah ummmm
    thats c++
    i could give you a translation of that into vb (a working example), but the problem is i don't have the syntax for declaring the CreateRgnFromFile api call in VB. If i had that i could give an example.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Sedgefield
    Posts
    337

    Question

    CreateRgnFromFile isn't an API call, its a function in the C++ code.

    The API used is ExtCreateRegion:

    VB Code:
    1. Public Declare Function ExtCreateRegion Lib "gdi32" Alias "ExtCreateRegion" (lpXform As xform, ByVal nCount As Long, lpRgnData As RGNDATA) As Long

    Dan

    Outside of a dog, a book is a man's best friend.
    Inside of a dog, it's too dark to read.

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