Ms access Access-从窗体中的图像控件导出图像
我一直在寻找一种从访问表单中提取图像的方法。在谷歌上搜索几乎总是指向。此软件允许导出存储在access表中OLE字段中的图像。这不是我想要的 我有一个带有一些徽标、标题和背景图像的表单。这些图像使数据库变得越来越大(因为它们嵌入到表单中)。我会提取它们,将它们与后端文件一起放在服务器上,并将它们添加回我的表单中,但这次是作为链接图像而不是嵌入图像 我希望我说清楚了。欢迎提出任何建议 编辑:添加了用于将图像控件的PictureData导出为图像文件的代码。此代码无法按预期工作。我发现PictureData是一个字节数组,但在将其复制到文件中后,每两个字符就有一个NUL字符Ms access Access-从窗体中的图像控件导出图像,ms-access,optimization,ms-access-2007,Ms Access,Optimization,Ms Access 2007,我一直在寻找一种从访问表单中提取图像的方法。在谷歌上搜索几乎总是指向。此软件允许导出存储在access表中OLE字段中的图像。这不是我想要的 我有一个带有一些徽标、标题和背景图像的表单。这些图像使数据库变得越来越大(因为它们嵌入到表单中)。我会提取它们,将它们与后端文件一起放在服务器上,并将它们添加回我的表单中,但这次是作为链接图像而不是嵌入图像 我希望我说清楚了。欢迎提出任何建议 编辑:添加了用于将图像控件的PictureData导出为图像文件的代码。此代码无法按预期工作。我发现Picture
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
图片数据是一个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
最后,这里是按预期工作的代码:从表单的图像控件导出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
如果您希望在另一个access数据库中重新使用该图像(即,您丢失了原始图像文件,但希望在其他地方使用它),则更简单的方法是使用外部数据->access菜单将对象(表单、报表等)导入新的access数据库 然后你可以复制粘贴你想要使用的图像控件 不幸的是,Access数据库之间图像控件的复制/粘贴无法按您的意愿工作
我很多年前就这样做了。目前我唯一能提供的解决方案是搜索未记录的系统commamd:712,例如SysCmd(712,PictureData)。经过多次搜索,我发现我需要将图像控件的PictureData保存到一个文件中。我发现PictureData是一个字节数组,但在将其复制到文件中后,每两个字符就有一个NUL字符。有什么想法吗?我想PictureData需要转换成Base64。谢谢你的帮助。你给我指了路。最后我需要一个转换。谢谢你的答复,但我相信这是一个PNG文件。将其转储到剪贴板,但他将读取我跳过的前8个字节中的信息,并将其保存为access保存的格式。您可以在问题中看到,我已找到此网站。您正在谈论的代码不支持PNG文件。不过还是要谢谢你的评论。这可能会帮助其他人。我也许能消除困惑。在MS Access中嵌入图像有两种方法(请参阅)。“旧”一个(“将所有图片数据转换为位图”)将所有图像转换为EMF,“新”一个(“保留源图像格式”)将保持原始格式不变。我有一个旧的mdb文件转换为accdb。表单在图像控件中嵌入了jpg图像。此过程非常适合将图像提取到emf。谢谢。方法不错,但这只会导出分辨率降低的图像。尽管对于报告来说,类似的方法是将报告导出为PDF格式并从中提取图像。