CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    Fading a picture

    How can I fade a PictureBox or ImageBox without flicker?

    It would have to be able to fade multiple colors at one time, obviously.

    Thanks.


  2. #2
    Guest

    Re: Fading a picture

    i would know how to fade it pixel by pixel...but that would be way too slow...
    you might look into the directX (directdraw & direct animation) sdks for this.


  3. #3
    Guest

    Re: Fading a

    Well, the DX SDKs are around 128 MB (unless I missed something here) and I can only use the Net at my school.

    When I used to use QB4.5, I could fade good in there. It wasn't slow or too hard. It should be just as easy in VB, and faster.

    Thanks though.


  4. #4
    Join Date
    Jan 2000
    Location
    Sweden, Kungsbacka
    Posts
    10

    Re: Fading a

    Yes, that's because QB uses indexed colors and just changes the palette.
    You can use DirectX and do it pixel by pixel, that should work and it should be pretty fast also.
    This doesn't work with the BitBlt API call (Actually, do NOT use this API at all if it is not really, really nescesary)


  5. #5
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Fading a

    Try something like this:

    private Declare Function BitBlt Lib "gdi32" (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 dwRop as Long) as Long
    private Declare Function CreateCompatibleDC Lib "gdi32" (byval hdc as Long) as Long
    private Declare Function CreateCompatibleBitmap Lib "gdi32" (byval hdc as Long, byval nWidth as Long, byval nHeight as Long) as Long
    private Declare Function DeleteDC Lib "gdi32" (byval hdc as Long) as Long
    private Declare Function DeleteObject Lib "gdi32" (byval hObject as Long) as Long
    private Declare Function SelectObject Lib "gdi32" (byval hdc as Long, byval hObject as Long) as Long
    private Declare Sub Sleep Lib "kernel32" (byval dwMilliseconds as Long)

    private Const SRCAND = &H8800C6
    private Const SRCCOPY = &HCC0020

    private Sub Command1_Click()
    Dim lDC as Long
    Dim lBMP as Long
    Dim W as Integer
    Dim H as Integer
    Dim lColor as Long

    W = ScaleX(Picture1.Picture.Width, vbHimetric, vbPixels)
    H = ScaleY(Picture1.Picture.Height, vbHimetric, vbPixels)
    lBMP = CreateCompatibleBitmap(Picture1.hdc, W, H)
    lDC = CreateCompatibleDC(Picture1.hdc)
    Call SelectObject(lDC, lBMP)
    BitBlt lDC, 0, 0, W, H, Picture1.hdc, 0, 0, SRCCOPY
    Picture1 = LoadPicture("")
    for lColor = 255 to 0 step -3
    Picture1.BackColor = RGB(lColor, lColor, lColor)
    BitBlt Picture1.hdc, 0, 0, W, H, lDC, 0, 0, SRCAND
    Sleep 10
    next
    Call DeleteDC(lDC)
    Call DeleteObject(lBMP)
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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

Featured