vbAccelerator - Contents of code file: frmAlphaResample.frmVERSION 5.00
Begin VB.Form frmAlphaResample
Caption = "Alpha Resampling Demo"
ClientHeight = 6480
ClientLeft = 2550
ClientTop = 2250
ClientWidth = 4935
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "frmAlphaResample.frx":0000
LinkTopic = "Form1"
ScaleHeight = 432
ScaleMode = 3 'Pixel
ScaleWidth = 329
Begin VB.PictureBox picAnimate
AutoSize = -1 'True
Height = 510
Left = 540
Picture = "frmAlphaResample.frx":1272
ScaleHeight = 450
ScaleWidth = 3600
TabIndex = 11
Top = 5940
Visible = 0 'False
Width = 3660
End
Begin VB.CommandButton cmdAnimate
Caption = "&Animate"
Height = 435
Left = 180
TabIndex = 10
Top = 5340
Width = 1155
End
Begin VB.HScrollBar hscScroll
Height = 255
LargeChange = 8
Left = 3300
Max = 64
Min = 2
SmallChange = 4
TabIndex = 8
Top = 1320
Value = 32
Width = 1575
End
Begin VB.CommandButton cmdBlendResampled
Caption = "Blend &Resampled with Background"
Enabled = 0 'False
Height = 495
Left = 1740
TabIndex = 7
Top = 1320
Width = 1455
End
Begin VB.CommandButton cmdBlendOriginal
Caption = "Blend O&riginal with Background"
Height = 495
Left = 120
TabIndex = 6
Top = 1320
Width = 1455
End
Begin VB.CommandButton cmdResampleWith
Caption = "Resample with Alpha ->"
Height = 495
Left = 1740
TabIndex = 5
Top = 720
Width = 1455
End
Begin VB.PictureBox picResampled
AutoRedraw = -1 'True
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 240
Left = 3600
ScaleHeight = 16
ScaleMode = 3 'Pixel
ScaleWidth = 16
TabIndex = 4
Top = 180
Width = 240
End
Begin VB.CommandButton cmdResampleNoAlpha
Caption = "Resample no Alpha ->"
Height = 495
Left = 1740
TabIndex = 3
Top = 120
Width = 1455
End
Begin VB.PictureBox picResult
AutoRedraw = -1 'True
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4635
TabIndex = 2
Top = 1980
Width = 4695
End
Begin VB.PictureBox picImage
AutoRedraw = -1 'True
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 960
Left = 180
Picture = "frmAlphaResample.frx":19C5
ScaleHeight = 64
ScaleMode = 3 'Pixel
ScaleWidth = 64
TabIndex = 1
Top = 180
Width = 960
End
Begin VB.PictureBox picBackground
AutoRedraw = -1 'True
AutoSize = -1 'True
Height = 1020
Left = 4200
Picture = "frmAlphaResample.frx":2247
ScaleHeight = 960
ScaleWidth = 7500
TabIndex = 0
Top = 120
Visible = 0 'False
Width = 7560
End
Begin VB.Label lblHScroll
Caption = "32"
Height = 255
Left = 3300
TabIndex = 9
Top = 1620
Width = 1575
End
End
Attribute VB_Name = "frmAlphaResample"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function TransparentBlt Lib "MSIMG32.DLL" ( _
ByVal hdcDest As Long, _
ByVal nXOriginDest As Long, _
ByVal nYOriginDest As Long, _
ByVal nWidthDest As Long, _
ByVal hHeightDest As Long, _
ByVal hdcSrc As Long, _
ByVal nXOriginSrc As Long, _
ByVal nYOriginSrc As Long, _
ByVal nWidthSrc As Long, _
ByVal nHeightSrc As Long, _
ByVal crTransparent As Long _
) As Long
Private m_cDIB As cDIBSection
Private m_cAlphaDib As cAlphaDibSection
Private Sub cmdAnimate_Click()
If (cmdAnimate.Caption = "&Animate") Then
cmdAnimate.Caption = "&Stop"
Dim iSize As Long
Dim iDir As Long
iDir = -1
iSize = 240
Dim cSource As cAlphaDibSection
Dim cResampled As cAlphaDibSection
Dim cBack As cAlphaDibSection
Set cBack = New cAlphaDibSection
cBack.CreateFromPicture picBackground.Picture
cBack.SetAlpha 255
Set cSource = New cAlphaDibSection
cSource.CreateFromPicture picAnimate.Picture
cSource.SetAlpha 255
cSource.SetColourTransparent &H0&
Do While cmdAnimate.Caption = "&Stop"
' Resample:
Set cResampled = cSource.AlphaResample(iSize)
' clear background:
cBack.AlphaPaintPicture Me.HDC, _
cmdAnimate.Left + cmdAnimate.Width + 16, cmdAnimate.Top, _
, , , , 32
' draw image
cResampled.AlphaPaintPicture Me.HDC, _
cmdAnimate.Left + cmdAnimate.Width + 24, cmdAnimate.Top + 8
iSize = iSize + iDir
If (iSize < 2) Then
iDir = 1
ElseIf (iSize > 230) Then
iDir = -1
End If
DoEvents
Loop
Else
cmdAnimate.Caption = "&Animate"
End If
End Sub
Private Sub cmdBlendResampled_Click()
' Set background:
Set picResult.Picture = picBackground.Picture
' Draw resampled image either using
' TransparentBlt or by using &H0& as
' transparent colour
' if no alpha channel available
Dim x As Long
Dim y As Long
If Not (m_cAlphaDib Is Nothing) Then
For x = 0 To picResult.Width Step m_cAlphaDib.Width
For y = 0 To picResult.Height Step m_cAlphaDib.Height
m_cAlphaDib.AlphaPaintPicture picResult.HDC, x, y
Next y
Next x
ElseIf Not (m_cDIB Is Nothing) Then
For x = 0 To picResult.Width Step m_cDIB.Width
For y = 0 To picResult.Height Step m_cDIB.Height
m_cDIB.PaintPicture picResult.HDC, x, y, crTransparent:=&H0&
Next y
Next x
End If
picResult.Refresh
End Sub
Private Sub cmdBlendOriginal_Click()
' Set background:
Set picResult.Picture = picBackground.Picture
' Draw source image, making &H0 transparent:
Dim x As Long
Dim y As Long
For x = 0 To picResult.Width Step picImage.Width
For y = 0 To picResult.Height Step picImage.Height
TransparentBlt picResult.HDC, x, y, _
picImage.Width, picImage.Height, _
picImage.HDC, _
0, 0, _
picImage.Width, picImage.Height, _
&H0&
Next y
Next x
End Sub
Private Sub cmdResampleNoAlpha_Click()
Set m_cAlphaDib = Nothing
' use cDib.Resample method:
Set m_cDIB = New cDIBSection
m_cDIB.CreateFromPicture picImage.Picture
Set m_cDIB = m_cDIB.Resample(picResampled.Width)
picResampled.Cls
m_cDIB.PaintPicture picResampled.HDC, crTransparent:=&H0&
picResampled.Refresh
cmdBlendResampled.Enabled = True
End Sub
Private Sub cmdResampleWith_Click()
Set m_cDIB = Nothing
' use custom alpha resample method:
Set m_cAlphaDib = New cAlphaDibSection
m_cAlphaDib.CreateFromPicture picImage.Picture
m_cAlphaDib.SetAlpha 255
m_cAlphaDib.SetColourTransparent &H0
Set m_cAlphaDib = m_cAlphaDib.AlphaResample(picResampled.Width)
picResampled.Cls
m_cAlphaDib.AlphaPaintPicture picResampled.HDC
picResampled.Refresh
'm_cAlphaDib.PreMultiplyAlpha
cmdBlendResampled.Enabled = True
End Sub
Private Sub hscScroll_Change()
lblHScroll.Caption = hscScroll.Value
picResampled.Move _
picResampled.Left, picResampled.Top, _
hscScroll.Value, hscScroll.Value
End Sub
Private Sub hscScroll_Scroll()
hscScroll_Change
End Sub
|
|