Results 1 to 12 of 12

Thread: alpha blending

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question

    can I alpha blend a image or picturebox control to what ever is behind it?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes if you know what's behind it in the first place
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question

    How?

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    For each pixel, you can average the red, green and blue components of the colour, using the ratio of the two alphas as a bias, so it's a weighted average.
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Or for alpha channels involved, multiply soruce component with alpha, and add target component multiplied by 1-alpha
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Most of us know this, but:

    HOW do you alpha-blend with a good framerate? Must you use GetObject and Get and Set Bitmap Bits? Or is there a DLL out there that returns an hDC or something?

    If there is, I'm sure we'd all like to know!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    DMA is the answer, have a look at them at http://www.ur.co.nz/ and check out the DMA samples that uses array pointers to manipulate bitmaps directly. Calling a C++ dll would be a lot faster though, if anyone have this i'd like to know.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    Why not using the AlphaBlend function????

    Here's the code taken from API Guide:

    Code:
    'This project requires two picture boxes
    'Both picture boxes should contain a picture
    Private Type BLENDFUNCTION
      BlendOp As Byte
      BlendFlags As Byte
      SourceConstantAlpha As Byte
      AlphaFormat As Byte
    End Type
    
    Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
    Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim BF As BLENDFUNCTION, lBF As Long
        'Set the graphics mode to persistent
        Picture1.AutoRedraw = True
        Picture2.AutoRedraw = True
        'API uses pixels
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        'set the parameters
        With BF
            .BlendOp = AC_SRC_OVER
            .BlendFlags = 0
            .SourceConstantAlpha = 128
            .AlphaFormat = 0
        End With
        'copy the BLENDFUNCTION-structure to a Long
        RtlMoveMemory lBF, BF, 4
        'AlphaBlend the picture from Picture1 over the picture of Picture2
        AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
    End Sub

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    lInt, lInt, lInt... ARGH!

    The programmer must've gotten kinda bored on that one.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    THANK YOU VERY MUCH!

    Thank you, Arcom!!!

    That saved me! Since it uses hDCs, I can also use it for DDRAW! BRILLIANT!

    Thank you Arcom, thank you!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Thumbs up

    Nice code Arcom, I'll look at it later when I got time.

  12. #12
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355
    just 1 thing: AlphaBlend isn't supported on Win95, so you'd have to distribute the new version of msimg32.dll with your app
    buzzwords are the language of fools

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