vbAccelerator - Contents of code file: frmBrightnessAndContrast.frmVERSION 5.00
Begin VB.Form frmBrightnessAndContrast
Caption = "vbAccelerator Brightness And Contrast Sample"
ClientHeight = 4755
ClientLeft = 2265
ClientTop = 2100
ClientWidth = 7725
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "frmBrightnessAndContrast.frx":0000
LinkTopic = "Form1"
ScaleHeight = 4755
ScaleWidth = 7725
Begin VB.HScrollBar hscBrightness
Height = 255
LargeChange = 64
Left = 4860
Max = 510
SmallChange = 32
TabIndex = 8
Top = 4320
Value = 255
Width = 1575
End
Begin VB.HScrollBar hscContrast
Height = 255
LargeChange = 40
Left = 4860
Max = 200
SmallChange = 10
TabIndex = 5
Top = 3960
Value = 100
Width = 1575
End
Begin VB.PictureBox picResult
Height = 3435
Left = 3900
ScaleHeight = 225
ScaleMode = 3 'Pixel
ScaleWidth = 241
TabIndex = 3
Top = 420
Width = 3675
End
Begin VB.PictureBox picSource
Height = 3435
Left = 120
ScaleHeight = 225
ScaleMode = 3 'Pixel
ScaleWidth = 241
TabIndex = 1
Top = 420
Width = 3675
End
Begin VB.CommandButton cmdSource
Caption = "Load I&mage..."
Height = 435
Left = 120
TabIndex = 0
Top = 3900
Width = 1455
End
Begin VB.Label lblBrightness
Caption = "&Brightness"
Height = 255
Left = 4020
TabIndex = 10
Top = 4320
Width = 855
End
Begin VB.Label lblBrightnessAmount
Height = 255
Left = 6540
TabIndex = 9
Top = 4320
Width = 675
End
Begin VB.Label lblContrastAmount
Height = 255
Left = 6540
TabIndex = 7
Top = 3960
Width = 675
End
Begin VB.Label lblContrast
Caption = "&Contrast"
Height = 255
Left = 4020
TabIndex = 6
Top = 3960
Width = 855
End
Begin VB.Label lblResult
BackColor = &H80000010&
Caption = " Result"
ForeColor = &H80000014&
Height = 255
Left = 3900
TabIndex = 4
Top = 60
Width = 3675
End
Begin VB.Label lblSource
BackColor = &H80000010&
Caption = " Source Image"
ForeColor = &H80000014&
Height = 255
Left = 120
TabIndex = 2
Top = 60
Width = 3675
End
End
Attribute VB_Name = "frmBrightnessAndContrast"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private m_cSourceImage As New cDIBSection
Private m_cResultImage As New cDIBSection
Private m_cProcess As New cBrightnessContrast
Private Function getContrast() As Double
Dim lV As Long
lV = hscContrast.Value
If (lV = 100) Then
getContrast = 1#
ElseIf (lV < 100) Then
' 100 == 1, 0 == 1/5
getContrast = 1# / (5# - (lV / 25#))
Else
' 100 == 1, 200 == 5
getContrast = (lV - 100#) / 25# + 1#
End If
End Function
Private Function getBrightness() As Long
getBrightness = hscBrightness.Value - 255
End Function
Private Sub process()
Dim Contrast As Double
Dim Brightness As Long
Contrast = getContrast()
lblContrastAmount.Caption = Contrast
Brightness = getBrightness()
lblBrightnessAmount.Caption = Brightness
m_cProcess.Contrast = Contrast
m_cProcess.Brightness = Brightness
m_cProcess.process m_cSourceImage, m_cResultImage
picResult.Refresh
End Sub
Private Sub openImage(ByVal sFile As String)
Dim sPic As StdPicture
Set sPic = LoadPicture(sFile)
m_cSourceImage.CreateFromPicture sPic
picSource.Refresh
m_cResultImage.Create m_cSourceImage.Width, m_cSourceImage.Height
hscContrast_Change
End Sub
Private Sub cmdSource_Click()
On Error GoTo ErrorHandler
Dim c As New cCommonDialog
Dim sFile As String
If c.VBGetOpenFileName(sFile, Filter:="Picture Files
(*.GIF;*.JPG;*.BMP)|*.GIF;*.JPG;*.BMP|All Files (*.*)|*.*",
DefaultExt:="BMP", Owner:=Me.hwnd) Then
openImage sFile
End If
Exit Sub
ErrorHandler:
MsgBox "Problem getting source image: [" & Err.Description & "]",
vbExclamation
Exit Sub
End Sub
Private Sub Form_Load()
Me.Show
Me.Refresh
On Error GoTo ErrorHandler
Dim sFile As String
sFile = App.Path
If (Right$(sFile, 1) <> "\") Then sFile = sFile & "\"
sFile = sFile & "woodpanel.jpg"
openImage sFile
Exit Sub
ErrorHandler:
MsgBox "Problem getting source image: [" & Err.Description & "]",
vbExclamation
Exit Sub
End Sub
Private Sub hscBrightness_Change()
process
End Sub
Private Sub hscBrightness_Scroll()
process
End Sub
Private Sub hscContrast_Change()
process
End Sub
Private Sub hscContrast_Scroll()
process
End Sub
Private Sub picResult_Paint()
m_cResultImage.PaintPicture picResult.hdc
End Sub
Private Sub picSource_Paint()
m_cSourceImage.PaintPicture picSource.hdc
End Sub
|
|