首页 > 解决方案 > 从 Access 导出图标图像的最佳方法?

问题描述

我在 Access 表单上有大约 50 个图标图像 (.ico),但是我没有将它们存储在磁盘上。我想将它们从 Access 导出到磁盘位置。

我在这个线程上尝试了建议的解决方案:

Access - 从表单中的图像控件导出图像

我无法打开生成的文件,可能是因为我的图像是 (.ico) 而不是 (.png)

编辑:我可以将图标复制到绘画中,将它们保存为 png,然后使用在线转换器将它们转换为图标。相当耗时,但它有效。

标签: vbams-access

解决方案


您可以使用此代码打击。

它会将所提供表单的所有图像控件的内容保存到同一文件夹中的文件中。

请注意,某些图像控件包含“奇怪的”二进制格式,每个工具可能无法正确显示这些格式。

此外,您必须注意在导出自己后分配正确的文件扩展名。

将代码放在一个新模块中,然后在设计视图中打开表单并像这样调用它:SaveAllImageControls Forms("MyForm")

Public Sub SaveAllImageControls(ByRef sourceForm As Form)
    Dim item As control
    For Each item In sourceForm.Controls: Do
        If item.ControlType <> acImage Then Exit Do
        If IsNull(item.PictureData) Then Exit Do

        Dim bArray() As Byte
        bArray = item.PictureData

        Dim filename As String
        filename = Application.CurrentDb.Name & "-" & sourceForm.Name & "-" & item.Name & ".binary"

        Dim fileNumber As Integer
        fileNumber = FreeFile

        Open filename For Binary As fileNumber
        Put fileNumber, , bArray
        Close fileNumber
    Loop While False: Next item
End Sub

推荐阅读