?? form1.frm
字號(hào):
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form Form1
Caption = "彩色與灰度"
ClientHeight = 4665
ClientLeft = 60
ClientTop = 345
ClientWidth = 6345
FillColor = &H00FFFFFF&
LinkTopic = "Form1"
ScaleHeight = 311
ScaleMode = 3 'Pixel
ScaleWidth = 423
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton CmdGray
Caption = "轉(zhuǎn)換"
Height = 375
Left = 1560
TabIndex = 4
Top = 4200
Width = 1095
End
Begin VB.CommandButton CmdSave
Caption = "保存"
Height = 375
Left = 4440
TabIndex = 3
Top = 4200
Width = 855
End
Begin MSComDlg.CommonDialog CmnDlg1
Left = 2040
Top = 1680
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
End
Begin VB.CommandButton CmdOpen
Caption = "打開(kāi)"
Height = 375
Left = 120
TabIndex = 2
Top = 4200
Width = 855
End
Begin VB.PictureBox Picture2
AutoRedraw = -1 'True
AutoSize = -1 'True
FillColor = &H00FFFFFF&
ForeColor = &H00FFFFFF&
Height = 3615
Left = 3240
ScaleHeight = 237
ScaleMode = 3 'Pixel
ScaleWidth = 173
TabIndex = 1
Top = 360
Width = 2655
End
Begin VB.PictureBox Picture1
AutoSize = -1 'True
Height = 3600
Left = 120
ScaleHeight = 236
ScaleMode = 3 'Pixel
ScaleWidth = 171
TabIndex = 0
Top = 360
Width = 2625
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CmdGray_Click()
'轉(zhuǎn)換為灰度圖像
Dim red As Integer
Dim green As Integer
Dim blue As Integer
Dim c As Long
Dim graycolor As Long
Dim x0 As Integer
Dim y0 As Integer
For x0 = 0 To Picture1.Width
For y0 = 0 To Picture1.Height
c = Picture1.Point(x0, y0)
red = (c And &HFF)
green = (c And 62580) / 256
blue = (c And &HFF00) / 65536
graycolor = (red + green + blue) / 3
Picture2.PSet (x0, y0), RGB(graycolor, graycolor, graycolor)
DoEvents
Next
Next
End Sub
Private Sub CmdOpen_Click()
'打開(kāi)文件并顯示在Picture1中
On Error GoTo Err_handle
CmnDlg1.DialogTitle = "打開(kāi)"
CmnDlg1.ShowOpen
Picture1.Picture = LoadPicture(CmnDlg1.FileName)
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
Exit Sub
Err_handle: Exit Sub
End Sub
Private Sub CmdSave_Click()
'保存轉(zhuǎn)換后的圖像
On Error GoTo Err_handle
CmnDlg1.DialogTitle = "保存"
CmnDlg1.Filter = ("位圖文件(*.bmp)|*.bmp")
CmnDlg1.ShowSave
SavePicture Picture2.Image, CmnDlg1.FileName
Err_handle: MsgBox Err.Description, vbOKOnly
Exit Sub
End Sub
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -