访问-从图像控件中以表单导出图像 [英] Access - Export images from Image controls in forms

查看:81
本文介绍了访问-从图像控件中以表单导出图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种从访问表单中提取图像的方法.在Google上进行的搜索几乎总是指向 OLEtoDisk .该软件允许导出存储在访问表内OLE字段中的图像.这不是我想要的.

I have been searching for a way to extract images from access forms. A search on Google will nearly always point to OLEtoDisk. This software allows to export images stored in OLE fields inside access tables. This is not what I want.

我有一个带有一些徽标,标题和背景图像的表格.这些图像使数据库变得越来越大(因为它们嵌入在表单中).我将提取它们,将它们与后端文件一起放置在我们的服务器上,然后将它们重新添加到我的表单中,但这一次是链接图像而不是嵌入式图像.

I have a form with some logos, headers and background images. Those images are making the database become bigger and bigger (because they are embedded in the form). I would extract them, place them on our server together with the back-end file and add them back to my forms but this time as linked images instead of embedded images.

我希望我能使自己清楚.欢迎任何建议.

I hope I am making myself clear. Any suggestions are welcome.

添加了我用于将Image控件的PictureData导出为图像文件的代码.此代码无法正常工作.我发现PictureData是一个字节数组,但是将其复制到文件中后,每两个字符得到一个NUL字符.

EDIT : Added the code I'm using to export an Image control's PictureData as an image file. This code doesn't work as intended. I found out that PictureData is a byte array but after copying it in a file, I get one NUL character every two characters.

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

推荐答案

最后,这是按预期工作的代码:从表单的Image控件中导出PNG图像.

Finally here is the code that worked as intended : Export a PNG image from a form's Image control.

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

这篇关于访问-从图像控件中以表单导出图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆