📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4335
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 4335
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 375
Left = 7680
TabIndex = 5
Top = 720
Width = 4575
End
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 360
Top = 120
Visible = 0 'False
Width = 1200
_ExtentX = 2117
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = ""
OLEDBString = ""
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton Command3
Caption = "显示保存后的存图片"
Height = 615
Left = 12360
TabIndex = 4
Top = 240
Width = 1335
End
Begin VB.TextBox Text2
Height = 375
Left = 7560
TabIndex = 3
Text = "Text2"
Top = 240
Width = 4695
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 6840
Top = 120
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text1
Height = 375
Left = 960
TabIndex = 2
Text = "Text1"
Top = 600
Width = 2775
End
Begin VB.CommandButton Command2
Caption = "保存"
Height = 735
Left = 5160
TabIndex = 1
Top = 360
Width = 1815
End
Begin VB.CommandButton Command1
Caption = "选择图片"
Height = 495
Left = 3840
TabIndex = 0
Top = 480
Width = 1095
End
Begin VB.Image Image2
Height = 5895
Left = 8640
Top = 1200
Width = 6135
End
Begin VB.Image Image1
Height = 5895
Left = 120
Top = 1200
Width = 7695
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim DataArr() As Byte
Dim Conn As String
Dim Rs As New ADODB.Recordset
Dim Id As Integer
Dim PT As Byte
Dim SQL As String
Dim LngOffset As Long, Chunks As Integer, LngTotaSize As Long
Dim Fragment As Integer, Chunk() As Byte, I As Long
Const ChunkSize As Integer = 2384
Dim Mediatemp As String
Private Sub Command1_Click()
With CommonDialog1
.Filter = "图片文件(*.bmp;*.jpg)|*.bmp;*.jpg"
.FilterIndex = 1
.FileName = m_DataBase
.DefaultExt = "mdf"
.Flags = cdlOFNHideReadOnly Or cdlOFNPathMustExist Or cdlOFNOverwritePrompt _
Or cdlOFNNoReadOnlyReturn
.DialogTitle = "照片取出路径"
'.ShowSave
.ShowOpen
m_path = .FileName
Text1.Text = m_path
Image1.Picture = LoadPicture(Text1.Text)
End With
End Sub
Private Sub Command2_Click()
Text2.Text = SavePicture(Text1.Text) '保存图片
End Sub
Private Function SavePicture(ByVal DataFile As String) '保存图片
Open DataFile For Binary As 1
Rs.Open "select * from ph ", Conn, adOpenKeyset, adLockOptimistic
If FileLen(DataFile) = True Then Close 1: Exit Function '文件大小为零的处理
Chunks = FileLen(DataFile) \ ChunkSize
Fragment = FileLen(DataFile) Mod ChunkSize
ReDim Chunk(Fragment) '根据文件长度定义动态数组大小
Get 1, , Chunk() '将一个已打开的磁盘文件读入数组变量之中
Rs.AddNew
Rs.Fields("Photo").AppendChunk Chunk()
'将得到的值写入数据库
ReDim Chunk(ChunkSize)
For I = 1 To Chunks
Get 1, , Chunk()
Rs.Fields("Photo").AppendChunk Chunk()
'将得到的值写入数据库
Next I
Close 1
Rs.Fields("ID") = 9
Rs.Update
Rs.Close
End Function
Private Function ShowPicture(ByVal DataFile As String) '保存图片
Rs.Open "select * from ph where id='" & Trim(Text3.Text) & "'", Conn, adOpenKeyset, adLockOptimistic
Rs.MoveLast
Open DataFile For Binary As 1
LngTotaSize = Rs.Fields("photo").ActualSize
Chunks = LngTotaSize \ ChunkSize
Fragment = LngTotaSize Mod ChunkSize
ReDim Chunk(Fragment)
Chunk() = Rs.Fields("photo").GetChunk(Fragment)
Put 1, , Chunk()
For I = I To Chunks
ReDim Chunk(ChunkSize)
Chunk() = Rs.Fields("photo").GetChunk(ChunkSize)
Put 1, , Chunk()
Next I
Close 1
Rs.Close
End Function
Private Sub Command3_Click()
Call ShowPicture("c:\temp.jpg") '显示图片
Image2.Picture = LoadPicture("c:\temp.jpg")
End Sub
Private Sub Form_Load()
Conn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=BooK_data;Data Source=127.0.0.1;PWD="
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -