请问怎样将picturebox中的图片存入数据库字段中?
在数据库的photo字段中有一个大图,现因为要用水晶报表打印照片字段,因此需要一个小图,我打算将它存在sphoto字段中。我现将photo中的大图按比例缩小后放在picturebox中,请问怎样将其存入sphoto中?
2010-01-09 09:45

2010-01-09 19:28
2010-01-10 15:11
2010-01-10 18:04
2010-01-11 09:07

2010-01-11 19:38
2010-01-11 23:48
2010-01-12 11:23

2010-01-12 13:41
程序代码:
Dim bit1() As Byte
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Function getbit(ByVal hbmp As Long, ByRef bit() As Byte)
Dim picinfo As BITMAP
GetObject hbmp, Len(picinfo), picinfo
ReDim bit(1 To picinfo.bmHeight * picinfo.bmWidth * 4)
GetBitmapBits hbmp, UBound(bit), bit(1)
End Function
Private Sub Command1_Click() '保存图片
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "这里写上连接你的SQLSERVER数据库的代码"
Conn.Open
Rs.Open "select * from [TmpPic]", Conn, 1, 3
Rs.AddNew
getbit Picture1.Image, bit1()
Rs("width") = Picture1.Width'记录下图片的宽度
Rs("height") = Picture1.Height'记录下图片的高度
Rs("photo").AppendChunk bit1()
Rs.Update
Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
Private Sub Command2_Click() '显示图片
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "这里写上连接你的SQLSERVER数据库的代码"
Conn.Open
Rs.Open "select * from [TmpPic]", Conn, 1, 1
ReDim bit1(1)
Picture2.Width = Rs("width")
Picture2.Height = Rs("height")
bit1 = Rs("photo").GetChunk(Rs("photo").ActualSize)
SetBitmapBits Picture2.Image, UBound(bit1), bit1(0)
Picture2.Refresh
Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
Private Sub Form_Load()
Command1.Caption = "保存图片"
Command2.Caption = "读取图片"
End Sub
Private Sub Picture1_Click() '给Pictrue1加载一幅图片
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub

2010-01-12 13:47