Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Fading in an image

Posted on 2003-03-16
Medium Priority
Last Modified: 2010-05-01
I am looking for a way to have an image fade in.  What I need to have happen is:  when running the picture would appear blacked out, and have small squares reveal one at a time until the whole image is revealed.

Thank you
Question by:egroegeinrub
LVL 11

Accepted Solution

supunr earned 800 total points
ID: 8149788
This is NOT a neat solution.  but might worth while trying this.  You have to put the image in an image control, not a picture box.  Need a image control called "Image1" and timer control called "Timer1"

Option Explicit

Dim imgIndex As Long
Dim Shape1(24) As Shape

Private Sub Form_Load()
    Dim i As Long
    Dim j As Long
    For i = 0 To 24
        Set Shape1(i) = Controls.Add("VB.Shape", "shape_" & i)
    Next i
    For i = 0 To 24
        Shape1(i).Width = Image1.Width / 5
        Shape1(i).Height = Image1.Height / 5
        Shape1(i).Move Int(i / 5) * Shape1(i).Width + Image1.Left, (i Mod 5) * Shape1(i).Height + Image1.Top
        Shape1(i).Visible = True
        Shape1(i).BackStyle = 0 'solid
        Shape1(i).FillStyle = 0 'solid
    Next i
End Sub

Private Sub ShowImage()
    Timer1.Interval = 50
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Shape1(imgIndex).Visible = False
    imgIndex = imgIndex + 1
    If (imgIndex > 24) Then
        imgIndex = 0
        Timer1.Enabled = False
    End If
End Sub

Good Luck!

Expert Comment

ID: 8149982
theres two methods a hard an easy way. the hard way isnt too hard though. hard way is to use GetDiBits and get the images rgb values stored into an array and then get the difference between the colors and a certain percentage to add.
so if you want the images to go through 10 steps till they are completely faded into the other, if pic1's red value starts at 0 and pic2's is 100 for that particular pixel you take 100-0 = 100 then get 10 percent
= 10 and then next time youll get 20% of the difference until they = the same
you dont have to change anything for subtracting cause the number youll get with be negative, it'll work out
ie. pic1 red = 50 pic2 red = 25
25-50 = -25
so when you add a % of that youll be taking away from pic1'a red not adding.
quick easy way is to make a picturebox and set the backcolor to black then bitblt the image onto it using (i believe SRCPAINT) then set the picture a little whiter and do the same till its white
so have variables for red green and blue and keep incrementing and set the backcolor to RGB(red,green,blue)
then use bitblt and SRCPAINT
the pic will fade from black. im not 100% sure it's SRCPAINT i dont have any of my source code right now, i had to format my drive and my programming stuff hasnt been copied from a backup hard drive yet.

Expert Comment

ID: 8532228
Hi egroegeinrub,
This old question (QID 20553028) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.

Expert Comment

ID: 8956487
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept supunr's comments as answer

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Expert Comment

ID: 8956488
nice code supunr.  Adding to my library

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question