Results 1 to 24 of 24

Thread: One color Transparency...

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    One color Transparency...

    Is there any way I can make only ONE color on my form transparent? I want to make the form invisible but keep any image data I may have on there (like from using .print or .line).

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    There is a method to create a rounded form, for example. This is made with a masked picture that tells which part of the form is visible and which is not. Would this help?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Have a look at this. This example has the masked already loaded in the form.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: One color Transparency...

    Try this... I think it is exactly what you want.

    Mc Brain if what you posted does this then sorry, it didn't sound like it

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by penagate
    Try this... I think it is exactly what you want.

    Mc Brain if what you posted does this then sorry, it didn't sound like it
    Not quite. I posted a simpler sample. An here is an even simpler way.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    Oops, forgot to mention this needs to be on Windows 98. I'll take a look at the examples now...

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: One color Transparency...

    Nove, true transparency is only supported on Windows 2000 and higher.
    You can still do funny shaped forms in Win 98 but no translucency effects.

  8. #8

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    Ok, then is there a way to make a certain color of a picture box transparent?

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by penagate
    Nove, true transparency is only supported on Windows 2000 and higher.
    You can still do funny shaped forms in Win 98 but no translucency effects.
    The code I posted works on W98. However, it is neither true transparency, nor translucent. Maybe it's not what you need.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: One color Transparency...

    Mc Brain when I run the 2nd project you posted I see white dots to the right of the black text. I have some other regioning code which doesn't do that.
    Code:
    Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    
    Public Function RegionFromImage(fRgnForm As Form, picBackground As PictureBox, ByVal lBackColor As Long) As Long
        Dim hRegion As Long
        Dim lpicHeight As Long
        Dim lpicWidth As Long
        Dim lRow As Long
        Dim lCol As Long
        Dim lStart As Long
        Dim hTempRegion As Long
        Dim lResult As Long
        
        hRegion = CreateRectRgn(0, 0, 0, 0)
        
        With picBackground
            lpicHeight = .Height / Screen.TwipsPerPixelY
            lpicWidth = .Width / Screen.TwipsPerPixelX
            
            For lRow = 0 To lpicHeight - 1
                lCol = 0
                Do While lCol < lpicWidth
                    Do While (lCol < lpicWidth) And _
                             (GetPixel(.hDC, lCol, lRow) = lBackColor)
                        lCol = lCol + 1
                    Loop
                    If lCol < lpicWidth Then
                        lStart = lCol
                        Do While (lCol < lpicWidth) And _
                                 (GetPixel(.hDC, lCol, lRow) <> lBackColor)
                            lCol = lCol + 1
                        Loop
                        If lCol > lpicWidth Then lCol = lpicWidth
                        hTempRegion = CreateRectRgn(lStart, lRow, lCol, lRow + 1)
                        lResult = CombineRgn(hRegion, hRegion, hTempRegion, RGN_OR)
                        Call DeleteObject(hTempRegion)
                    End If
                Loop
            Next
        End With
        
        RegionFromImage = hRegion
        SetWindowRgn fRgnForm.hwnd, hRegion, True
    End Function
    Basically just call RegionFromImage from the Form_Initialize sub. Unlike your example it does need a picture box with an image in it. Also you need to pass the background (transparent) colour.

    Nove if you are printing text/lines to the form, to use this code just print them to a picture box instead, and pass the background colour of the picture box to the funciton.

  11. #11
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by penagate
    Mc Brain when I run the 2nd project you posted I see white dots to the right of the black text. I have some other regioning code which doesn't do that.
    Code:
    Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    
    Public Function RegionFromImage(fRgnForm As Form, picBackground As PictureBox, ByVal lBackColor As Long) As Long
        Dim hRegion As Long
        Dim lpicHeight As Long
        Dim lpicWidth As Long
        Dim lRow As Long
        Dim lCol As Long
        Dim lStart As Long
        Dim hTempRegion As Long
        Dim lResult As Long
        
        hRegion = CreateRectRgn(0, 0, 0, 0)
        
        With picBackground
            lpicHeight = .Height / Screen.TwipsPerPixelY
            lpicWidth = .Width / Screen.TwipsPerPixelX
            
            For lRow = 0 To lpicHeight - 1
                lCol = 0
                Do While lCol < lpicWidth
                    Do While (lCol < lpicWidth) And _
                             (GetPixel(.hDC, lCol, lRow) = lBackColor)
                        lCol = lCol + 1
                    Loop
                    If lCol < lpicWidth Then
                        lStart = lCol
                        Do While (lCol < lpicWidth) And _
                                 (GetPixel(.hDC, lCol, lRow) <> lBackColor)
                            lCol = lCol + 1
                        Loop
                        If lCol > lpicWidth Then lCol = lpicWidth
                        hTempRegion = CreateRectRgn(lStart, lRow, lCol, lRow + 1)
                        lResult = CombineRgn(hRegion, hRegion, hTempRegion, RGN_OR)
                        Call DeleteObject(hTempRegion)
                    End If
                Loop
            Next
        End With
        
        RegionFromImage = hRegion
        SetWindowRgn fRgnForm.hwnd, hRegion, True
    End Function
    Basically just call RegionFromImage from the Form_Initialize sub. Unlike your example it does need a picture box with an image in it. Also you need to pass the background (transparent) colour.

    Nove if you are printing text/lines to the form, to use this code just print them to a picture box instead, and pass the background colour of the picture box to the funciton.
    I think you see those dots because the image is aliased. The image should get an anti-aliased. That's an example I downloaded some time ago.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: One color Transparency...

    That makes sense, they must be almost white but not quite.

    If so then I think you example is better than mine because it doesn't require a picturebox.

  13. #13

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    Penagate, where/how do I use your code?

  14. #14
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by Nove
    Penagate, where/how do I use your code?
    Here's a sample with penagate's code. However... it seems to be a little slow (with large images). Unfortunately... it won't make it as transparent as almost all men would want. (You'll understand when you see the sample).
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  15. #15

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    I clicked the command button, but nothing happened. Was something supposed to?

  16. #16
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Some pixels of the image should be turned into "transparent" (and see the light blue form's backcolor. Bear in mind, that the model's top is not perfectly white but has a lot of shades.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  17. #17

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    I replaced the picture with just a white background, I couldn't really see any difference with the picture there. Works though, now maybe I can implement the two...

  18. #18
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: One color Transparency...

    transLUCENT effects require win 2000 (well, they don't, but 2000 has api support for them)

    transPARENT is an easier beast and can be done in 98

  19. #19

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    What's the difference?

  20. #20

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: One color Transparency...

    Hey, I need to make the form transparent in color, but actually tangible, as in I can see what's underneath it but when i click on that area I click on the form, not the junk underneath. Possible?

  21. #21
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by Nove
    Hey, I need to make the form transparent in color, but actually tangible, as in I can see what's underneath it but when i click on that area I click on the form, not the junk underneath. Possible?
    No. That's a translucent form. And can only be achieve with W2K Up (I don't know if it can be done in NT either).
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  22. #22
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: One color Transparency...

    McBrain that is a terrible example
    nice picture though

    And yeah, maybe this whole transparency/translucency thing need clarifying. Translucency (semi-opacity) and full transparency can both be achieved by alpha blending. Full transparency can also be achieved by regioning which is what the examples in this thread are doing. Basically it just consists of telling Windows where to cut the edges of the form out. Alpha blending on the other hand makes either the whole form or pixels of a certain colour on the form, semi-opaque (a bit like Mc Brain's picture )

    The API needed for alpha-blending is only available in Win 2K+. The APIs used for regioning however are available in Win 95+.

  23. #23
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: One color Transparency...

    Quote Originally Posted by penagate
    McBrain that is a terrible example
    nice picture though
    Sorry. He was saying he wanted to do it a picture, and I thought it should be with a photo.... and don't have much photos for an example.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  24. #24
    Hyperactive Member Eyes.Only's Avatar
    Join Date
    Oct 2001
    Location
    Minnesota
    Posts
    347

    Question Re: One color Transparency...

    When you cant control what image is going to be used so you can make sure its anti-aliased you can always seperate the colors down to their RGB components and check them to see if the difference between them all is minute, sounds like a lot of checking but its not too bad and helps a lot on some images.

    Since regions is the subject here and is spawned from the very same beginnings as my project, i have a question...

    After deciding the 'BlueScreening' method wasnt quite what i needed I ended up drawing my images manually (just semi-complex shapes) by creating regions, and using FillRgn and FrameRgn. Worked good, however I did it on a UserControl. Inside that usercontrol i have another nested usercontrol which plays animations. my problem? when i play the animation in the nested control, my entire control with the painted region is invalidated and disappears leaving only the nested animation control showing. Its not clipping...so...what am i missing?

    If i lock the window update, then the animation isnt seen, so i need to lock everything but the animation...

    I dont know...im tired and irritated heh.

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