📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "Bmp 与 Jpg 相互转换"
ClientHeight = 3780
ClientLeft = 45
ClientTop = 330
ClientWidth = 5460
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3780
ScaleWidth = 5460
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.OptionButton optDo
Caption = " Jpg文件转为Bmp文件"
Height = 360
Index = 1
Left = 2625
TabIndex = 13
Top = 180
Width = 2160
End
Begin VB.OptionButton optDo
Caption = " Bmp文件转为Jpg文件"
Height = 360
Index = 0
Left = 195
TabIndex = 12
Top = 180
Value = -1 'True
Width = 2160
End
Begin VB.CommandButton cmdSaveAs
Caption = "另存图片"
Height = 375
Left = 120
TabIndex = 5
Top = 2925
Width = 975
End
Begin VB.HScrollBar hscrQuality
Height = 375
LargeChange = 10
Left = 1440
Max = 100
Min = 1
TabIndex = 3
Top = 1725
Value = 75
Width = 3255
End
Begin VB.CheckBox chkHoldColor
Caption = "保留颜色"
Height = 375
Left = 225
TabIndex = 2
Top = 1725
Value = 1 'Checked
Width = 1095
End
Begin VB.CommandButton cmdBmpLoad
Caption = "加载图片"
Height = 375
Left = 120
TabIndex = 1
Top = 840
Width = 975
End
Begin MSComDlg.CommonDialog dlgFile
Left = 4935
Top = 135
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Frame Frame1
Height = 495
Left = 120
TabIndex = 7
Top = 2205
Width = 4575
Begin VB.OptionButton optColorBits
Caption = " 2色"
Enabled = 0 'False
Height = 255
Index = 0
Left = 195
TabIndex = 11
Top = 180
Width = 855
End
Begin VB.OptionButton optColorBits
Caption = " 16色"
Enabled = 0 'False
Height = 255
Index = 1
Left = 1155
TabIndex = 10
Top = 180
Width = 855
End
Begin VB.OptionButton optColorBits
Caption = " 256色"
Enabled = 0 'False
Height = 255
Index = 2
Left = 2115
TabIndex = 9
Top = 180
Width = 855
End
Begin VB.OptionButton optColorBits
Caption = " 24位色"
Enabled = 0 'False
Height = 255
Index = 3
Left = 3195
TabIndex = 8
Top = 180
Value = -1 'True
Width = 1215
End
End
Begin VB.Label labDestFile
AutoSize = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "DestFile"
Height = 240
Left = 1200
TabIndex = 6
Top = 3045
Width = 4185
WordWrap = -1 'True
End
Begin VB.Label labQuality
AutoSize = -1 'True
Caption = "75"
Height = 180
Left = 4920
TabIndex = 4
Top = 1845
Width = 180
End
Begin VB.Label labSourceFile
AutoSize = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "SourceFile"
Height = 240
Left = 1200
TabIndex = 0
Top = 960
Width = 4155
WordWrap = -1 'True
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function BmpToJpg Lib "JpgVSbmp" (ByVal lpBmpFileNameForIn As String, ByVal lpJpgFileNameForOut As String, ByVal bColor As Boolean, ByVal nQuality As Long) As Boolean
Private Declare Function JpgToBmp Lib "JpgVSbmp" (ByVal lpJpgFileNameForIn As String, ByVal lpBmpFileNameForOut As String, ByVal iColorBit As Long) As Boolean
' 加载图片
Private Sub cmdBmpLoad_Click()
dlgFile.InitDir = App.Path
dlgFile.FileName = ""
If optDo(0).Value = True Then ' 加载Bmp
dlgFile.Filter = "Bmp 文件(*.bmp)|*.bmp"
Else
dlgFile.Filter = "Jpg 文件(*.jpg)|*.Jpg"
End If
' 选择文件
dlgFile.ShowOpen
' 确认是否存在此文件
If dlgFile.FileName <> "" And Dir(dlgFile.FileName) <> "" Then
labSourceFile.Caption = dlgFile.FileName
End If
End Sub
Private Sub cmdSaveAs_Click()
Dim bColor As Boolean
Dim nColorBit As Long
Dim i As Integer
dlgFile.InitDir = App.Path
dlgFile.FileName = ""
If optDo(0).Value = True Then ' 另存为Jpg
dlgFile.Filter = "Jpg 文件(*.jpg)|*.Jpg"
Else ' 另存为Jpg
dlgFile.Filter = "Bmp 文件(*.bmp)|*.bmp"
End If
' 确定文件
dlgFile.ShowSave
' 确认是否设置了文件名
If dlgFile.FileName <> "" Then
labDestFile.Caption = dlgFile.FileName
If optDo(0).Value = True Then ' 另存为Jpg
If chkHoldColor.Value = vbChecked Then
bColor = True
Else
bColor = False
End If
BmpToJpg labSourceFile, labDestFile, bColor, hscrQuality.Value
Else ' 另存为Bmp
' 计算Bmp的颜色位数
For i = 0 To 3
If optColorBits(i).Value = True Then
nColorBit = 2 ^ (i + 1)
Exit For
End If
Next i
If nColorBit = 2 Then
nColorBit = 1
End If
JpgToBmp labSourceFile, labDestFile, nColorBit
End If
End If
End Sub
Private Sub hscrQuality_Change()
labQuality.Caption = hscrQuality.Value
End Sub
Private Sub optDo_Click(Index As Integer)
Dim i As Integer
If Index = 0 Then ' BmpToJpg
For i = 0 To 3
optColorBits(i).Enabled = False
Next i
Else ' JpgToBmp
For i = 0 To 3
optColorBits(i).Enabled = True
Next i
End If
chkHoldColor.Enabled = Not optColorBits(0).Enabled
hscrQuality.Enabled = chkHoldColor.Enabled
labQuality.Enabled = hscrQuality.Enabled
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -