How to save images in Access DB

Example requests & Code samples for GdPicture Toolkits.
Post Reply
MCHSRAS
Posts: 6
Joined: Thu Apr 24, 2008 2:16 pm

How to save images in Access DB

Post by MCHSRAS » Tue May 13, 2008 8:32 pm

In the samples, there isn't any code on how to save an image in an Access db. Is there a way to save the image in an AccessDB?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How to save images in Access DB

Post by Loïc » Thu May 15, 2008 2:28 pm

Hi,

You can download the last package of GdPicture Pro. It include an Access sample which shows how to load / save an image using an OLE field.



1 - Create a table (table1) with 3 fields:
ID: numeric (primary key)
Title: String (50)
Image: OLE

2 - into a form add:

Code: Select all

Private Sub Form_Load()
   Me.RecordSource = "SELECT * FROM table1"
End Sub
3 - Code to append the native image of an Imaging object to the OLE field:

Code: Select all

Dim arBytes() As Byte
      
If Imaging1.SaveAsByteArray(arBytes, 0, "jpg") = 0 Then
   Me.Recordset.Edit
   Me.Recordset.Fields("Image").AppendChunk arBytes
   Me.Recordset.Update
   MsgBox "Image saved"
End If
Erase arBytes

4 - Code to read an image from the OLE field:

Code: Select all

Dim arbyte() As Byte

arbyte = Me.Recordset.Fields("Image").GetChunk(0, LenB(Me.Recordset.Fields("Image")))
Call Imaging1.CreateImageFromByteArray(arbyte)
  
Erase arbyte
Best regards,

Loïc Carrère

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest