Steve Luktisch

Steve Luktisch

  • NA
  • 1
  • 3.8k

Draw.image

Oct 30 2010 11:27 PM
Hello all

I am having a problem with GDI+, I'm using it to draw an image onto a form; the image has some transparent color as the background. i am using getpixel to let me know if I click on the picture or the background. this works fine until I have a tick move the picture somewhere else on the form, at this point getpixel does not work unless you click where the image was when it was first drawn. Here is the code used in the forms paint event:

bmp is declared globally so it can be used by the getpixel subroutine in the mouse down event.

  Dim g As Graphics = Graphics.FromImage(bmp)
        g.Dispose()
        Dim attr As New ImageAttributes

        ' Set the transparency color key based on the upper-left pixel
        ' of the image.
        ' Uncomment the following line to make all black pixels transparent:
        attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0))

                ' Draw the image using the image attributes.
        Dim dstRect As New Rectangle(xpoint, ypoint, bmp.Width, bmp.Height)
        e.Graphics.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height, _
            GraphicsUnit.Pixel, attr)