09-09-2003, 06:37 AM
Hi, I am not sure if this is possible, so i wonder if somebody could help me? I have two images, identical, apart from one has a red triangle over part of it. I want the form to contain one picture and one slider bar. When the slider bar is at the left hand side i want image 1 to be shown in the picture box, when the slider is at the right hand side i want image 2 to be visible, and when the slider is in the middle, both image 1 and 2 will be visible, but at half transparency. So in effect like a cross fader for images. Is this possible and how the hell do i do it???
09-09-2003, 06:49 AM
Yes, it's possible, but you need to scale the bits in the painting everytime the slider moves (and you are going to need at least two picture boxes... 3 is good).
First, you need to use some functions for examining and setting bits (SetPixel and GetPixel API work for me)....
Now, when you move the scrollbar, you will want to get a percentage of each pixel of each picture... the percentage depends upon the scrollbar location.
Then, when the scrollbar changes, you need to loop through the pixels of the picture and set them into your main picturebox accordingly. Hopefully your picture isn't too large.
Set all of the pictureboxes scalemodes to Pixels...
Note that this may not run as fast as you want it to...
Dim LX As Integer, LY As Integer, Color1 As Long, Color2 As Long, FinalColor As Long, Percentage As Currency
'Calculate the percentage based on where the slider is...
Percentage = (Slider.Value - Slider.Min) / (Slider.Max - Slider.Min)
'If Slider.Min is 0, then this can be simplified
'Loop through the pixels... yes it's a double loop
For LX = 0 To PicBox.ScaleWidth - 1
For LY = 0 To PicBox.ScaleHeight - 1
'Get the pixel LX and LY from each picture
Color1 = GetPixel(LeftPicture.hDC, LX, LY)
Color2 = GetPixel(RightPicture.hDC, LX, LY)
'FinalColor is the color after the calculations have been completed.
'Notice how I take only a percent of Color2 and add that to the
'remaining percent of Color1.
'Set this Color into the PicBox of your choice.
FinalColor = Percentage * Color2 + (1 - Percentage) * Color1
09-09-2003, 07:05 AM
thanks for the reply. I am a bit of newbie, so i need things a little simpler. I have got a form with two picture boxes and have declared the SetPixel and GetPixel API's and put your code in, with a horizontal scroller named slider. When i run it it says "for without next"? do you have a version of this in a finished form so that i can have a look and mess around with it myself?
09-09-2003, 07:45 AM
Look like ice has unplugged...
end of code is missing ...
I would gess something like :
FinalPicBox.setpixel (LX,LY, Finalcolor)
09-09-2003, 08:07 AM
ok cheers, i got it to work, buts its sooooooooooo slooooooooooow. Are there any other methods that allow a fast transition between two images?
09-09-2003, 08:14 AM
I think I came accross some API for transparence of controls, I'll have a look and see what I can find...
09-09-2003, 08:35 AM
See if you can't do anything with this one ...
'This project requires two picture boxes
'Both picture boxes should contain a picture
Const AC_SRC_OVER = &H00
Private Type BLENDFUNCTION
BlendOp As Byte
BlendFlags As Byte
SourceConstantAlpha As Byte
AlphaFormat As Byte
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()
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
.BlendOp = AC_SRC_OVER
.BlendFlags = 0
.SourceConstantAlpha = 128
.AlphaFormat = 0
'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
09-09-2003, 08:52 AM
Yup, that looks great, but......... i can only seem to get it to work at run time, if i put it in a timer, or on a button click it don't work, any ideas why?
09-09-2003, 09:22 AM
No worries i have found a sample of what i want here:
09-09-2003, 09:43 AM
I remain speachless ...
Just fantastic !