doup Level: Scholar
 Registered: 16-06-2004 Posts: 32
|
printing picture (datareport)
hi, if you have been wondering how to print picture object in your datareport(picture stored in the database let say MS ACCESS) here is the simple approch. first your picture must be stored in binary format so you will have among other fields these 2 fields picture field (object-binary) and fileLeigth(long -data type).
in ur data report put image object in any section(section1)
declaration of few variable
Dim ByteData() As Byte
Dim DestFileNum As Integer
Dim DiskFile, pif As String
Dim FileLength As Long
'open your database and connect to the table
If Rs!FileLength > 0 Then
DiskFile = ""
DiskFile = App.Path & "\picfile.bmp"
If Len(Dir$(DiskFile)) > 0 Then
Kill DiskFile
End If
FileLength = Rs.Fields("fileLength").Value
DestFileNum = FreeFile
Open DiskFile For Binary As DestFileNum
Numblocks = FileLength / BlockSize
LeftOver = FileLength Mod BlockSize
ByteData() = Rs("picture_field").GetChunk(LeftOver)
Put DestFileNum, , ByteData() 'write data from a variable to disk file
For i = 1 To Numblocks
ByteData() = Rs("picture_field").GetChunk(BlockSize)
Put DestFileNum, , ByteData()
Next i
Close DestFileNum
picf = App.Path & "\picfile.bmp"
End If
Erase ByteData
Set drMember.DataSource = Rs
'trick we writepicture file to HD then read it from there
Set Me.Sections("Section1").Controls.Item("Image2").Picture = LoadPicture(picf)
end if |
hope it can helps
[Edited by doup on 26-01-2005 at 02:02 PM GMT]
[Edited by doup on 09-02-2005 at 11:17 AM GMT]
____________________________
peter
|