我一直在寻找一种从访问表单中提取图像的方法。对Google的搜索几乎总是指向OLEtoDisk。该软件允许导出存储在访问表内的OLE字段中的图像。这不是我想要的。
我有一个带有一些徽标,标题和背景图片的表单。这些图像使数据库变得越来越大(因为它们嵌入在表单中)。我会提取它们,将它们与后端文件一起放在我们的服务器上,然后将它们添加回我的表单,但这次是链接图像而不是嵌入图像。
我希望自己清楚明白。欢迎任何建议。
编辑:添加了我用于将Image控件的PictureData导出为图像文件的代码。此代码无法按预期工作。我发现PictureData是一个字节数组,但在文件中复制之后,我每两个字符就得到一个NUL字符。
Public Function savePict(pImage As Access.Image)
Dim fname As String 'The name of the file to save the picture to
Dim iFileNum As Double
fname = Environ("Temp") + "\temp.png" ' Destination file path
iFileNum = FreeFile 'The next free file from the file system
Open fname For Binary Access Write As iFileNum
Dim tbyte As Variant
Dim i As Double
'Write the byte array to the file
For i = 0 To Len(pImage.PictureData)
Put #iFileNum, , pImage.PictureData(i)
Next i
Close #iFileNum
End Function
答案 0 :(得分:3)
图片数据是一个EMF文件,包装为8个字节。 这是您修改的例程,使用正确的文件扩展名
Public Function savePict(pImage As Access.Image)
Dim fname As String 'The name of the file to save the picture to
Dim iFileNum As Double
Dim bArray() As Byte, cArray() As Byte
Dim lngRet As Long
fname = Environ("Temp") + "\temp.emf" ' Destination file path
iFileNum = FreeFile 'The next free file from the file system
' Resize to hold entire PictureData prop
ReDim bArray(LenB(pImage.PictureData) - 1)
' Resize to hold the EMF wrapped in the PictureData prop
ReDim cArray(LenB(pImage.PictureData) - (1 + 8))
' Copy to our array
bArray = pImage.PictureData
For lngRet = 8 To UBound(cArray)
cArray(lngRet - 8) = bArray(lngRet)
Next
Open fname For Binary Access Write As iFileNum
'Write the byte array to the file
Put #iFileNum, , cArray
Close #iFileNum
End Function
答案 1 :(得分:2)
最后,这里是按预期工作的代码:从表单的Image控件中导出PNG图像。
Public Function savePict(pImage As Access.Image)
Dim fname As String 'The name of the file to save the picture to
fname = Environ("Temp") + "\temp.png" ' Destination file path
Dim iFileNum As Double
iFileNum = FreeFile 'The next free file from the file system
Dim pngImage As String 'Stores the image data as a string
pngImage = StrConv(pImage.PictureData, vbUnicode) 'Convert the byte array to a string
'Writes the string to the file
Open fname For Binary Access Write As iFileNum
Put #iFileNum, , pngImage
Close #iFileNum
End Function
答案 2 :(得分:0)
如果您要在另一个访问数据库中重复使用该图像(即您丢失了原始图像文件,但想在其他地方使用它),则更容易导入对象(表单,报表等)使用外部数据进入新的Access数据库 - >访问菜单。
然后,您只需将图像控件复制粘贴到您想要使用的位置......
不幸的是,Access数据库之间的图像控件的复制/粘贴无法正常工作。
答案 3 :(得分:0)