Retrieving images from the database for Aspose Power Point


#1

Here is a question. I have a picture, stored as an image on a database table. I wish to add this image to a picture frame. If I have a static image, stored in a fixed location, I can do something like this:

Dim pf As PictureFrame = Nothing
pf = FindPictureFrame(slide, "Goose")
If Not (pf Is Nothing) Then '

Dim picid As Integer = pres.Pictures.Add(New Picture(pres, MapPath ("Goose.jpg")))
pf.PictureId = picid
End If

What code can I use if the image is stored in a database table, in order to retrieve it from a table, and place in in the Aspose Power Point picture?


#2

Dear Randy,

You can use something like that:

Dim strCmd As String = "SELECT Image FROM ImagesTable WHERE ......"
Dim cmd As SqlCommand = New SqlCommand(strCmd, sqlConn)

Dim b() As Byte = CType(cmd.ExecuteScalar(), Byte())
If b.Length > 0 Then
Dim stream As MemoryStream = New MemoryStream(b)

Dim pf As PictureFrame = Nothing
pf = FindPictureFrame(slide, "Goose")
If Not (pf Is Nothing) Then
Dim picid As Integer = pres.Pictures.Add(New Picture(pres, stream))
pf.PictureId = picid
End If
End If


#3

Alex:
Great! Thanks!
RandyBig Smile