Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image fading in Direct Draw 7 2

Status
Not open for further replies.

slowATthought

Programmer
Dec 2, 2003
56
0
0
US
I need to be able to fade an image to any color in Direct Draw. Any help is.... um.... helpful.
 
True, ESquared, I will look.

TheTuna, I like the site. I already learned how to change fonts in DD. :) I checked out alphablending in DD, and it told me about a vbDABL. It's a dll, and I'm going to try using it.

Strongm, because I would use GDI's alphablend, but vbDABl is sopposed to be very fast (which I like). Thanks for the suggestion, though.

Thanks, everyone, especially strongm, because you have been helping me on this for more than a week.
 
Glad to help, and reguarding Strongm, there's a reason his name shows up at the top of the forum MVP list... he's very helpful, and very knowledgable.

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!

Ever feel like you're banging your head against a tree? I did, so I cut down the tree.
 
Well, if you really think that a 3rd party DLL (that only works properly on 16-bit color images) is faster/easier than a built-in function...

 
I think it's more likely that he didn't fully read the tutorial, therefore didn't realize it only supports 16 bit color.

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!

Ever feel like you're banging your head against a tree? I did, so I cut down the tree.
 
Uh... I actually didn't. I still haven't gotten it to download. I feel stupid. I hadn't checked back on this thread.

Strongm, if you read this, I'm all ears about the GDI AlphaBlend function.
 
Um...if I get the chance...

Basically, I'm only likely to be posting short answers for the next couple of weeks or so as I get used to being a new dad...
 
Way to go Strongm!

[fish] No Dolphins were harmed in the posting of this message... Dolphin Friendly Tuna!

Ever feel like you're banging your head against a tree? I did, so I cut down the tree.
 
Code:
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Type BLENDFUNCTION
  BlendOp As Byte
  BlendFlags As Byte
  SourceConstantAlpha As Byte
  AlphaFormat As Byte
End Type
' BlendOp:
Private Const AC_SRC_OVER = &H0
' AlphaFormat:
Private Const AC_SRC_ALPHA = &H1

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Private Declare Function AlphaBlend Lib "MSIMG32.dll" ( _
  ByVal hdcDest As Long, _
  ByVal nXOriginDest As Long, _
  ByVal nYOriginDest As Long, _
  ByVal nWidthDest As Long, _
  ByVal nHeightDest As Long, _
  ByVal hdcSrc As Long, _
  ByVal nXOriginSrc As Long, _
  ByVal nYOriginSrc As Long, _
  ByVal nWidthSrc As Long, _
  ByVal nHeightSrc As Long, _
  ByVal lBlendFunction As Long _
) As Long

Private Sub Command1_Click()
    Dim lBlend As Long
   Dim bf As BLENDFUNCTION
   Dim alpha As Long

   ' Draw the first picture:
   bf.BlendOp = AC_SRC_OVER
   bf.BlendFlags = 0
   bf.SourceConstantAlpha = 128
   bf.AlphaFormat = 0
   CopyMemory lBlend, bf, 4
   AlphaBlend Me.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBlend

    ' Make sure picture2 is same size as picture 1
    Picture2.Width = Picture1.Width
    Picture2.Height = Picture1.Height
    
    ' OK now blend towards the colour held in Picture 2
    For alpha = 0 To 95
        bf.SourceConstantAlpha = alpha
        CopyMemory lBlend, bf, 4
        AlphaBlend Me.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hDC, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, lBlend
        Sleep 100
    Next
End Sub

Private Sub Form_Load()

    Form1.Picture = Picture1.Picture
    Picture1.AutoSize = True
    
    Picture2.BackColor = RGB(255, 0, 0)
    
    Picture1.AutoRedraw = True
    Picture1.ScaleMode = vbPixels
    Picture2.ScaleMode = vbPixels
    Picture2.AutoRedraw = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top