Access - Export images from Image controls in forms

∥☆過路亽.° 提交于 2020-01-30 01:03:25

问题


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.

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

回答1:


The picture data is an EMF file, with a wrapper of 8 bytes. This is your routine modified to use the correct file extension

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



回答2:


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



回答3:


If you are looking to re-use the image in another access database (ie you lost the original image file, but want to use it elsewhere), a far easier method would be to import the object (form, report etc) into your new Access database using the External Data -> Access menu.

You can then just copy paste the image control where you want to use it...

Unfortunately copy/paste of image controls between Access databases doesnt work as you'd like.




回答4:


  1. Take your form that has a background image or AutoFormat that you like
  2. Right-click on the form in the Navigation Pane and select Export >> XML
  3. On the first page of the wizard, select a destination to drop some files (Desktop is fine)
  4. A small dialog will then appear with three check boxes
  5. Select the first option (Data) and third option (Presentation) and then click OK
  6. Click the Close button on the last page of the wizard after the export is complete


来源:https://stackoverflow.com/questions/10792426/access-export-images-from-image-controls-in-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!