View previous topic :: View next topic |
Author |
Message |
WaqasK
Joined: 21 Oct 2006 Posts: 32
|
Posted: Sun Dec 03, 2006 4:47 pm Post subject: Display a blob image |
|
|
Guys,
I'm having trouble displaying a blob image from a mySQL database in the Virtual Tree. I used the following code to display the image through a VDO recordset:
Code: | Public Property Flag() As Image
Get
Dim photoField As ADODB.Field = Fields("Flag")
Dim sPhoto As Image = Nothing
If photoField.ActualSize > 0 Then
Dim data As Byte() = CType(photoField.GetChunk(photoField.ActualSize), Byte())
Dim stream As New MemoryStream(data)
sPhoto = New Bitmap(stream)
stream.Close()
End If
Return sPhoto
End Get
Set(ByVal Value As Image)
Dim photoField As ADODB.Field = Fields("Flag")
photoField.Value = Nothing
If Not (Value Is Nothing) Then
Dim stream As New MemoryStream
' A bug in Image.Save means that we can't just call Photo.Save. If the image
' was read previously from a memory stream then it remains attached and
' refuses to save to another memory stream without giving a "Cannot access closed stream"
' exception. The workaround is to copy the image to another bitmap and save that
'
Dim bm As New Bitmap(Value)
bm.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
photoField.AppendChunk(stream.ToArray())
bm.Dispose()
stream.Close()
End If
If Not IsEditing Then
Me.Update(False)
End If
End Set
End Property |
However when I compile I get the text "System.Drawing.Bitmap" in the column field. All other fields (text and integers) load correctly. What am I doing wrong here? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Dec 03, 2006 11:34 pm Post subject: |
|
|
This is not a VDO problem - but how you have setup your Virtual Tree bindings. You need to change the cell binding for the row/column containing the image to set the ShowPreview property to true and the ShowText property to false. You may also want to modify the PreviewSize property. _________________ Infralution Support |
|
Back to top |
|
|
WaqasK
Joined: 21 Oct 2006 Posts: 32
|
Posted: Tue Dec 05, 2006 11:17 am Post subject: |
|
|
yeah you're right, I reallt should have put this in the virtual tree boards. Sorry about that. But yeah i was modifying the bindings in code and what you suggested worked fine. Thanks! |
|
Back to top |
|
|
|