通过写二进制的方法,把数据流写进去

解决方案 »

  1.   

    这个函数是将图形从数据库中拷出到文件,存入类似。
    Function CopyFieldToFile(rst As Recordset, fd As String, strFileName As String) As String
     Dim FileNum As Integer
     Dim Buffer() As Byte
     Dim BytesNeeded As Long
     Dim Buffers As Long
     Dim Remainder As Long
     Dim Offset As Long
     Dim R As Integer
     Dim i As Long
     Dim ChunkSize As Long ChunkSize = 65536
     BytesNeeded = rst(fd).ActualSize
        If BytesNeeded > 0 Then
           ' Calculate the number of buffers needed to copy
            Buffers = BytesNeeded \ ChunkSize
            Remainder = BytesNeeded Mod ChunkSize
            ' Get a unique, temporary filename:        If Dir(strFileName) <> "" Then
                Kill strFileName
            End If
            ' Copy the bitmap to the temporary file chunk by chunk:
            FileNum = FreeFile
            Open strFileName For Binary As #FileNum
            frmP1.Show
            frmP1.Timer1.Interval = 100
            For i = 0 To Buffers - 1
                DoEvents
               ReDim Buffer(ChunkSize)
               Buffer = rst(fd).GetChunk(ChunkSize)
               Put #FileNum, , Buffer()
               Offset = Offset + ChunkSize
            Next        ' Copy the remaining chunk of the bitmap to the file:
            ReDim Buffer(Remainder)
            Buffer = rst(fd).GetChunk(Remainder)
            Put #FileNum, , Buffer()
            Close #FileNum
            frmP1.Timer1.Interval = 0
            Unload frmP1
        End If
        CopyFieldToFile = strFileName
    End Function