alpha-blend / fade-in controls? 
Author Message
 alpha-blend / fade-in controls?

Anyone know of any controls or sample code that would illustrate how take
two images (image or picture control) that are the same size, one on top of
the other, and fade from one image to the other.  Seems like it should be
straight forward, however I've scoured the net and haven't found much.  The
only control I've found so far (can't remember the name) required me to load
the images from a file at runtime!  Not very efficient.

Any ideas/suggestions are appreciated.

And by the way, I know nothing regarding graphics and VB.

-jef



Wed, 02 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?
look the AnimateWindow() at MSDN



Quote:
> Anyone know of any controls or sample code that would illustrate how take
> two images (image or picture control) that are the same size, one on top
of
> the other, and fade from one image to the other.  Seems like it should be
> straight forward, however I've scoured the net and haven't found much.
The
> only control I've found so far (can't remember the name) required me to
load
> the images from a file at runtime!  Not very efficient.

> Any ideas/suggestions are appreciated.

> And by the way, I know nothing regarding graphics and VB.

> -jef



Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Quote:
> look the AnimateWindow() at MSDN

That will only work on Win2K, the alpha transparency isn't supported in
Win9x or WinME.
As an alternative solution, try this:
Add two picture box's to a form, put your start image in picture 1, and your
end image in picture 2 (Preferably the same size).  Then paste this code in
and run:

'*** START CUT ***'

Private Declare Function GetPixel Lib "gdi32" _
    (ByVal hDC As Long, ByVal X As Long, _
    ByVal Y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" _
    (ByVal hDC As Long, ByVal X As Long, _
    ByVal Y As Long, ByVal crColor As Long) As Long

Dim Fading As Boolean

Const NumFrames = 10 'Number of fade frames

Private Sub Form_Load()
    With Form1
        .AutoRedraw = True
        .ScaleMode = vbPixels
    End With

    With Picture1
        .AutoRedraw = True
        .ScaleMode = vbPixels
        .Visible = False
        .AutoSize = True
    End With

    With Picture2
        .AutoRedraw = True
        .ScaleMode = vbPixels
        .Visible = False
        .AutoSize = True
    End With
End Sub

Private Sub Form_Click()
    Dim PicWid As Integer, PicHgt As Integer
    Dim SrcPic() As Pixel
    Dim DestPic() As Pixel
    Dim DrawX As Integer, DrawY As Integer
    Dim FadeLoop As Single
    Dim FadeStep As Single

    If Fading Then Exit Sub
    Fading = True

    Form1.Picture = Picture1.Picture
    Form1.Caption = "Scanning..."
    DoEvents

    With Picture1
        PicWid = .ScaleWidth - 1
        PicHgt = .ScaleHeight - 1

        'Allocate some memory to store the images
        ReDim SrcPic(PicWid, PicHgt) As Pixel
        ReDim DestPic(PicWid, PicHgt) As Pixel

        'Scan the images into memory
        For ScanX = 0 To PicWid
            For ScanY = 0 To PicHgt
                SrcPic(ScanX, ScanY) = LongToPix( _
                    GetPixel(.hDC, ScanX, ScanY))
                DestPic(ScanX, ScanY) = LongToPix( _
                    GetPixel(Picture2.hDC, ScanX, ScanY))
            Next ScanY
        Next ScanX

        Form1.Caption = "Fading (0%)"

        FadeStep = 255 / NumFrames

        'Main fade loop
        For FadeLoop = 0 To 255 Step FadeStep
            For DrawX = 0 To PicWid
                For DrawY = 0 To PicHgt
                    SetPixelV Form1.hDC, DrawX, DrawY, _
                        PixToLong(TransPix(SrcPic(DrawX, DrawY), _
                        DestPic(DrawX, DrawY), FadeLoop / 255))
                Next DrawY
            Next DrawX

            Form1.Caption = "Fading (" & _
                Int(((FadeLoop + FadeStep) / 255) * 100) & "%)"
            Form1.Refresh
        Next FadeLoop
    End With

    'Show the final image, then swap the original two
    ' (So it fades back next time)
    Form1.Picture = Picture2.Picture
    Picture2.Picture = Picture1.Picture
    Picture1.Picture = Form1.Picture
    Form1.Caption = "Done!"

    Fading = False
End Sub

'*** END CUT **'

Click the form to show the animation, it's a lot faster when compiled, but
still reasonably slow unfortunately.  For more speed interlace the
transparency frames, or convert it to DIB's (Or both!)
Hope this helps,

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?
I forgot to mention that you'll need my PixLib module (Free off my site),
just add that to the project then the code will run.
Sorry,

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Well first off your way is very inefficiant this way is much better and
works on win98

Public Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long,
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As
Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal
widthSrc As Long, ByVal heightSrc As Long, ByVal blendFunct As Long) As
Boolean

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As
Any, Source As Any, ByVal Length As Long)

Type BLENDFUNCTION
  BlendOp As Byte
  BlendFlags As Byte
  SourceConstantAlpha As Byte
  AlphaFormat As Byte
End Type
                            '//// Second effect
                            Dim Blend As BLENDFUNCTION, BlendLng As Long
                            For Y = 1 To 255 Step 10
                            DoEvents
                            Blend.SourceConstantAlpha = 0 + Y
                            CopyMemory BlendLng, Blend, 4
                            Picture1.Cls
                            AlphaBlend Picture1.hdc, 0, 0,
Picture2.ScaleWidth, Picture2.ScaleHeight, _
                            Picture2.hdc, 0, 0, Picture2.ScaleWidth,
Picture2.ScaleHeight, BlendLng
                            'Picture1.Refresh
                            Next Y
                            '//// End Effect

Have fun



Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Quote:
> Well first off your way is very inefficiant this way is much better and
> works on win98

<Code snipped>

Then you have to make sure the system is Win98 and they have a compatible
copy of msimg32.dll.  My method will work for all builds of windows and you
have complete control over it.  If you put it in a DIB and use lookup tables
to speed up the inner loops then you'll find the performance similar to that
of your proposed method.

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Thanks for everyone's input.  I've gone with the AlphaBlend API out of
laziness.  I'm not to worried about only supporting Win2K.

-jef



Quote:
> > Well first off your way is very inefficiant this way is much better and
> > works on win98

> <Code snipped>

> Then you have to make sure the system is Win98 and they have a compatible
> copy of msimg32.dll.  My method will work for all builds of windows and
you
> have complete control over it.  If you put it in a DIB and use lookup
tables
> to speed up the inner loops then you'll find the performance similar to
that
> of your proposed method.

>     Mike

>  -- EDais --

> WWW: Http://Members.xoom.com/EDais/





Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Quote:
> Thanks for everyone's input.  I've gone with the AlphaBlend API out of
> laziness.  I'm not to worried about only supporting Win2K.

AlphaBlend() is Win98 only, the AnimateWindow() method is Win2K only

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?
Hmmmm.....  I'm developing under Win2K with VB6 SP3 and AlphaBlend() is
working just fine.  It's very fast as well...

I played around a little bit with AnimateWindow() with little success.  I
downloaded a project from VBCode.com (I think that's where it was) and was
able to do fade-in and other effects, however, there was a tremendous amount
of code included.  It was subclassing the form and doing all sorts of other
things that seemed like too much work.  (I'm lazy...did I say that before?)
It wasn't just as simple as calling the API.    I tried to do a simple call
using the API and couldn't get it to work at all.  Also, I'm trying to
manipulate a picturebox image and all of the samples I found were specific
to doing the effects on a Form.

-jef



Quote:
> > Thanks for everyone's input.  I've gone with the AlphaBlend API out of
> > laziness.  I'm not to worried about only supporting Win2K.

> AlphaBlend() is Win98 only, the AnimateWindow() method is Win2K only

>     Mike

>  -- EDais --

> WWW: Http://Members.xoom.com/EDais/





Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Quote:
> Hmmmm.....  I'm developing under Win2K with VB6 SP3 and AlphaBlend() is
> working just fine.  It's very fast as well...

There could be a version of msimg32.dll supplied with your build of Win2K.

Quote:
> I played around a little bit with AnimateWindow() with little success.  I
> downloaded a project from VBCode.com (I think that's where it was) and was
> able to do fade-in and other effects, however, there was a tremendous
amount
> of code included.  It was subclassing the form and doing all sorts of
other
> things that seemed like too much work.  (I'm lazy...did I say that
before?)
> It wasn't just as simple as calling the API.    I tried to do a simple
call
> using the API and couldn't get it to work at all.  Also, I'm trying to
> manipulate a picturebox image and all of the samples I found were specific
> to doing the effects on a Form.

Also AnimateWindow() shouldn't need any subclassing, have a look about for
more examples of it.  I seem to remember one that was basically one line and
a few declares.  If you need to convert your code to use a picture box
rather than a form then it should simply be a case of replacing any
references to the form's hWnd/hDC with the picture box's.  If you need
further help then paste code here and I or others will have a look at it for
you.
Hope this helps,

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 03 Apr 2003 03:00:00 GMT  
 alpha-blend / fade-in controls?

Mike,

Quote:
> > Thanks for everyone's input.  I've gone with the AlphaBlend API out of
> > laziness.  I'm not to worried about only supporting Win2K.

> AlphaBlend() is Win98 only, the AnimateWindow() method is Win2K only

According to my MSDN Library
AlphaBlend() is available on Win2k and Win98 or later.
same story for AnimateWindow().

Check the little section at the end of each function in the MSDN called
"Requirements".  I think I just posted about this last week???

Hope this helps,
-Ray Mercer
MS-MVP Visual Basic



Fri, 04 Apr 2003 12:28:16 GMT  
 alpha-blend / fade-in controls?

Quote:
> According to my MSDN Library
> AlphaBlend() is available on Win2k and Win98 or later.
> same story for AnimateWindow().

AnimateWindow() works in Win98, but not with the alpha blending flag which
the question was originally about (A long time ago ;)
It will slide windows in of make them grow from a point, but not fade in
like you can do with Win2K.

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Sat, 05 Apr 2003 08:24:08 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. fading of two pictures (blend one picture into the other)

2. per pixel alpha blending

3. per pixel alpha blending

4. Alpha Blending

5. alpha blending puzzle

6. alpha blending w/o directx

7. Alpha Blended Usercontrol For Translucent Effect

8. alpha blending textures in Retaind Mode

9. Alpha Blending

10. 2D alpha blending

11. DirectDraw Alpha Blending?

12. Alpha blending *tutorial*

 

 
Powered by phpBB® Forum Software