Results 1 to 15 of 15

Thread: invisible

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Smile invisible

    how can I make part of a picture invisible? What I mean is, that if you wanted to put it in a picturebox, you would be able to see the backcolor through it, like a PNG washout thing, which is what they call it in microsofft office.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    If it's a .gif make it's background color transparent. If it's a .png I hear you cannot load it into a picturebox so look here for info about PNG

    http://www.vbforums.com/showthread.php?t=506545

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Re: invisible

    how can I make the background colour transparent?

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    If it's a GIF you will need some application that will allow you to load the GIF image and then set it's transparent color. For a free and easy one to use download Microsoft's Gif Animator.

    Google for Microsoft GIF Animator Application and you will find several places to download it.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: invisible


  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    Well that's really cool. Opens the door for alot of neat stuff

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    I added a second Picturebox and called it Picture2. It contains a bitmap.

    One question:

    How do you get it to draw the picture in Picture1 on top of the picture in the Picture2?

    I can get it to work as long as Picture1 is drawn on the Form but not if I want Picture1 to be drawn on the picture in Picture2.

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: invisible

    Need to change it slightly, something like,....
    Code:
        DrawTransPicture Picture1.Picture, 100, 100, RGB(255, 0, 255), Picture2
    Code:
    Public Sub DrawTransPicture(img As StdPicture, ImageX As Long, ImageY As Long, ImgTransColour As Long, pic As PictureBox)
        Dim hbmDc As Long
        Dim hBmp As Long
        Dim hBmpOld As Long
        Dim bmp As BITMAP
       
        If img.Type = vbPicTypeBitmap Then
            hBmp = img.Handle
            hbmDc = CreateCompatibleDC(0&)
            If hbmDc <> 0 Then
                hBmpOld = SelectObject(hbmDc, hBmp)
                If GetObject(hBmp, Len(bmp), bmp) <> 0 Then
                    Call TransparentBlt(pic.hdc, ImageX, ImageY, bmp.bmWidth, bmp.bmHeight, hbmDc, 0, 0, bmp.bmWidth, bmp.bmHeight, ImgTransColour)
                End If
                Call SelectObject(hbmDc, hBmpOld)
                DeleteObject hBmpOld
                DeleteDC hbmDc
            End If
        End If
    End Sub

  9. #9
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: invisible

    BTW, what I do is pass the hDC of the object instead of the pic box for destination , it's more flexible for future usage.
    Code:
    ' put pic1 on form1
    TransPicture Picture1.Picture, 100, 100, vbMagenta, Form1.hdc
    ' put pic1 on pic2
    TransPicture Picture1.Picture, 100, 100, vbMagenta, Picture2.hdc
    Code:
    Public Sub TransPicture(img As StdPicture, X As Long, _
    Y As Long, TransColor As Long, DestHdc As Long)
        
        Dim hbmDc As Long
        Dim hBmp As Long
        Dim hBmpOld As Long
        Dim bmp As BITMAP
       
        If img.Type = vbPicTypeBitmap Then
            hBmp = img.Handle
            hbmDc = CreateCompatibleDC(0&)
            If hbmDc <> 0 Then
                hBmpOld = SelectObject(hbmDc, hBmp)
                If GetObject(hBmp, Len(bmp), bmp) <> 0 Then
                    Call TransparentBlt(DestHdc, X, Y, bmp.bmWidth, bmp.bmHeight, _
                    hbmDc, 0, 0, bmp.bmWidth, bmp.bmHeight, TransColor)
                End If
                Call SelectObject(hbmDc, hBmpOld)
                DeleteObject hBmpOld
                DeleteDC hbmDc
            End If
        End If
    End Sub

  10. #10
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    I tried something similar to your example and it didn't work. Then I tried your example and still it didn't work.

    EDIT

    OK, never mind. All three worked. My first attempt and your two examples. The problem is that in the code that I copied the action took place in the Resize event which upon load probably executed the functions but was then erased when the Form became visible. So when I stretched the form a bit the picture then was displayed on the picture box


    EDIT EDIT

    I think the Resize event is the wrong place to start that stuff. Maybe it should be in the Paint event instead.


    EDIT EDIT EDIT

    Nope, the Paint event won't work.

    That whole method there is something wrong with it because the picture will dissapear if something else moves on top of the Form.


    EDIT EDIT EDIT EDIT

    OK, it has to go in the Picture2 Paint event.
    Last edited by jmsrickland; Jan 31st, 2008 at 11:53 PM.

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: invisible

    Quote Originally Posted by jmsrickland
    OK, it has to go in the Picture2 Paint event.
    Or you could set the destinations AutoRedraw to True.

  12. #12
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    I tried that and it won't draw at all. If you use that API on the Form the Form needs to be AutoRedraw = False and if you use it for a Picturebox then that needs to be AutoRedraw = False also.

  13. #13
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: invisible

    Ya guess your right, with Autodraw enabled and running the code from a button I had to do a pic=image,

    TransPicture Picture1.Picture, 20, 20, vbMagenta, PicDest.hdc
    PicDest.Picture = PicDest.Image
    TransPicture Picture3.Picture, 50, 0, vbMagenta, PicDest.hdc
    PicDest.Picture = PicDest.Image

  14. #14
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: invisible

    Yeah, even better but just don't do that in the Paint Event
    Last edited by jmsrickland; Feb 1st, 2008 at 02:16 PM.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Re: invisible

    what if I want to paint it onto an image control and want to still see the stuff behind the image control in the background?

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