Trucos Varios I
Fade de una imagen
' To change the colors, simply click on the picture boxes on the top. This demonstration was coded By Heian
' This is the same code used to fade the picture box in Mindworks Fader 1.0 For this you will need a CommonDialog box and 4 picture boxes. Picture1 is for the fade itself, Picture2 is color 1 Picture3 is color 2, and Picture 4 is so that you can change the width of picture1 Set everything to Scalemode 3 and All the picture boxes to AutoRedraw = true
Option Explicit
' The RGB Combined Type
Private Type RGBComb
Red As Long
Green As Long
Blue As Long
End Type
' I use this type to define the backcolors of the pictures with another sub I have in this code. It's a little easier when using the common dialog control to change the colors. If you were using sliders or scroll bars, simply use the values of the scrollbars to change the colors of R G and B like Blue1 = Hscroll1.Value: Red1 = HScroll2.Value
Dim Col1 As RGBComb
Dim Col2 As RGBComb
Private Sub Form_Load()
Picture2.BackColor = 0
Picture3.BackColor = 0
End Sub
Private Sub Form_Resize()
On Error Resume Next
Picture4.Width = Me.ScaleWidth - 5
If Picture1.Width > Picture4.Width Then
Picture1.Width = Picture4.Width
End If
End Sub
Private Sub Picture1_Click()
On Error Resume Next
Dim Col1R, Col1G, Col1B, Col2R, Col2G, Col2B
Dim CDiffRed, CDiffGreen, CDiffBlue
Dim CFadeRed, CFadeGreen, CFadeBlue
Dim Fade As Double
' ^ All the variables needed for the calculation of the fade. Col1/2 is Colors one and two. Col1/2/rgb is going to be used as the RGB Values of the colors CDiff is the difference between the colors and CFade is the step it is going to use. Fade is the Variable Used in the actual fading
Col1R = Col1.Red
Col1G = Col1.Green
Col1B = Col1.Blue
Col2R = Col2.Red
Col2G = Col2.Green
Col2B = Col2.Blue
' ^ Starts preparing for all the calculations by setting all of the different variables in the RGB Combinations to thier own variables
CDiffRed = -(Col1R - Col2R)
CDiffGreen = -(Col1G - Col2G)
CDiffBlue = -(Col1B - Col2B)
' ^ Calculates the difference betwen the colors for fading
CFadeRed = CDiffRed / Picture1.ScaleWidth
CFadeGreen = CDiffGreen / Picture1.ScaleWidth
CFadeBlue = CDiffBlue / Picture1.ScaleWidth
' ^ Calculates the step variable for the fading of the colors
For Fade = 0 To Picture1.ScaleWidth
Picture1.Line (Fade, 0)-(Fade, Picture1.ScaleHeight) , RGB(Col1R, Col1G, Col1B)
' ^ Draws a Vertical line the color of the current fade
Col1R = Col1R + CFadeRed
Col1G = Col1G + CFadeGreen
Col1B = Col1B + CFadeBlue
' ^ Boosts or lowers the red green and blue falues for the next pass Goes on to the next color
Next Fade
End Sub
Private Sub Picture2_Click()
' Shows the common dialog color
CommonDialog1.ShowColor
' Sets the picture's color to the selected color
Picture2.BackColor = CommonDialog1.Color
Col1 = GetRGBFromLong(Picture2.BackColor)
End Sub
Private Sub Picture3_Click()
' Same as Picture 2
CommonDialog1.ShowColor
Picture3.BackColor = CommonDialog1.Color
Col2 = GetRGBFromLong(Picture3.BackColor)
End Sub
' Gets the RGB And stores it in the RGB Combined type
Private Function GetRGBFromLong(ColorLong As Double) As RGBComb
' Temporary values
Dim tmpred As Long
Dim tmpgreen As Long
Dim tmpblue As Long
tmpblue = Int(ColorLong / 65536)
tmpgreen = Int((ColorLong - (65536 * tmpblue)) / 256)
tmpred = ColorLong - (65536 * tmpblue + 256 * tmpgreen)
' Sets the Values to what they are (Red Green and Blue)
If tmpred > 256 Then tmpred = 256
If tmpgreen > 256 Then tmpgreen = 256
If tmpblue > 256 Then tmpblue = 256
' Error trapping before it become an error
GetRGBFromLong.Red = tmpred
GetRGBFromLong.Green = tmpgreen
GetRGBFromLong.Blue = tmpblue
End Function
Private Sub Picture4_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture4.Cls
Picture4.Line (0, 0)-(X, Picture4.ScaleHeight), vbBlue, BF
Picture1.Width = X
End Sub
Private Sub Picture4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If X <= Picture4.ScaleWidth And X > 0 Then
Picture4.Cls
Picture4.Line (0, 0)-(X, Picture4.ScaleHeight), vbBlue, BF
Picture1.Width = X + 4
End If
End If
End Sub
|