如何控制显示图片在大小?从SQL image字段中读出来图片能否不直接读进image里,不需要存储??
下面的代码是能正确从SQL数据库是读出图片的,但是我觉得有两个地方需要改进
1 最好修改成不需要写到C盘去,能否直接读到image控件或者pictuer控件中去吗?
2 显示的图自不能控件大小,图片原来是多,就显示为多大,很不美观....
Private Sub 读出image字段,测试是OK ()
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=.;Initial Catalog=456;User Id=sa;Password=;"
Set rs = New ADODB.Recordset
rs.Open "Select * from yuangong where ygname='" & Text1.Text & "'", cn, adOpenKeyset, adLockOptimistic
If rs.EOF = True Then
MsgBox "没有该员工的记录"
Else
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("ygpicuter").Value '这是要写到C盘去的,能否直接读进Image2或Picture1.吗??
mstream.SaveToFile "c:\publogo.jpg", adSaveCreateOverWrite
Picture1.Picture = LoadPicture("c:\publogo.jpg") '使用两种方法进行显示'
Image2.Height = 60 '不起作用,图片原来是多大,就是会显示多大
Image2.Width = 60
Image2.Picture = LoadPicture("c:\publogo.jpg")
Text4.Text = rs("ygname")
Text5.Text = rs("ygchusheng")
Label5.Caption = rs("ygname") & "出生日期"
mstream.Close
Set mstream = Nothing
End If
rs.Close
cn.Close
End Sub
[解决办法]
你Image2.Picture = LoadPicture("c:\publogo.jpg")之后再把存的删掉
直接读不会,我都是先存储再删掉