将 Blob 图像导入 ms Access 报告的异常 [英] Exception on importing Blob image into ms Access report
问题描述
在 Access 2013 报告中,我通过链接表连接到 Oracle DB 视图.一个 View 字段是 BLOB 类型并保存之前存储在那里的图像.
In an Access 2013 Report I connect to an Oracle DB View via a Linked Table. One View field is of type BLOB and holds images that have been previously stored there.
在我的访问报告中,链接表有一个OLE 对象"类型的字段(名为 BILD_INHALT).映射到 Oracle DB 中的 BLOB 字段.
In my Access Report the linked table has a field (named BILD_INHALT) of type "OLE Object" that maps to the BLOB field in Oracle DB.
在报告视图中,我创建了一个图像"字段(名为 MST_Image)必须加载图像,并按以下方式初始化:
In the report view, I created an "Image" field (named MST_Image) has to load the image and it is initialized in the following way:
If Len(RS![BILD_INHALT]) > 0 Then
Me.MST_Image.PictureData = RS![BILD_INHALT]
End If
在运行时,当我使用来自 Oracle 的内容初始化 MST_Image.PictureData 时,出现以下异常.
At run time I get the following exception when I initialize MST_Image.PictureData with the content coming from Oracle.
我在互联网上查看了有关此(非常古老的)主题的更多文档,但找不到有关此特定问题的任何信息.
I check on internet about further documentation about this (very old) topic, but I could not find anything about this specific issue.
推荐答案
该错误不言自明:Microsoft Access 中的图像控件可以绑定到文件位置,也可以设置为 .dib
图像(设备无关位图格式,一种较为晦涩的图像格式).
The error is somewhat self-explanatory: an image control in Microsoft Access can be either bound to a file location, or can be set to a .dib
image (device independent bitmap format, one of the more obscure image formats).
不过,解决这个问题并不容易.
Working around it, though, is not that easy.
您可以通过多种方式解决该限制:
You can work around that limitation in several ways:
- 使用支持多种图像格式的 ActiveX 控件(可以找到多种格式)
- 将图像保存到磁盘的临时文件夹中,并将图像控件源设置为其所在位置
- 使用网络浏览器控件,并使用 HTML
<img/>
标记显示您的图像,使用 嵌入的 BASE64 图像
- Use an ActiveX control that supports multiple image formats (there are multiple to be found)
- Save the image to disk in a temporary folder, and set the images control source to its location
- Use a web browser control, and use the HTML
<img />
tag to display your image, using an embedded BASE64 image
这是方法 3 的示例代码:
Here is the example code for approach 3:
首先,我们需要能够将包含在 OLE 对象中的二进制代码转换为 BASE64:
First, we need to be able to convert the binary code contained in the OLE object to BASE64:
Public Function ToBase64(Bytes As Variant) As String
Dim XMLElement As Object
Set XMLElement = CreateObject("Msxml2.DOMDocument.6.0").createElement("tmp")
XMLElement.DataType = "bin.base64"
XMLElement.nodeTypedValue = Bytes
ToBase64 = Replace(XMLElement.Text, vbLf, "")
End Function
然后,我们可以使用网页浏览器控件,将带有 BASE64 编码图像的网页插入其中:
Then, we can use a web browser control, and insert a web page with the BASE64-encoded image into it:
Public Sub InsertImageInControl()
Dim wb As Object
Set wb = MyWebbrowserControl.Object
With wb
.Navigate2 "about:blank"
Do Until .ReadyState = 4 '=READYSTATE_COMPLETE
'This is a somewhat inefficient way to wait, but loading a blank page should only take a couple of milliseconds
DoEvents
Loop
.Document.Open
.Document.Write "<!DOCTYPE html><HTML><HEAD><TITLE>A</TITLE></HEAD><BODY scroll=""no"" style=""margin: 0px; padding: 0px;"">"
.Document.Write "<img alt="""" style=""width:100%; margin: 0px; padding: 0px;"" src=""data:image/jpg;base64,"
.Document.Write ToBase64(MyOLEObject.Value)
.Document.Write """ />"
.Document.Write "</BODY></HTML>"
.Document.Close
End With
End Sub
其中 MyWebbrowserControl
是您的网络浏览器控件的名称,image/jpg
是您的图像类型,而 MyOLEObject
是您的 OLE 对象.
Where MyWebbrowserControl
is the name of your webbrowser control, image/jpg
is your image type, and MyOLEObject
is your OLE object.
提示:
- 不要使用 WebBrowser ActiveX 控件,而应使用 Access 附带的控件.否则,您将获得带有无法删除的 3d 边框的过时版本的 Internet Explorer.
- 将网页浏览器控件的控件源设置为
="about:blank"
,将其初始化为空白页面
- Don't use the WebBrowser ActiveX control, but use the one that comes with Access. Else, you will get an outdated version of Internet Explorer with a 3d border that can't be removed.
- Set the control source for the web browser control to
="about:blank"
to initialize it as a blank page
这篇关于将 Blob 图像导入 ms Access 报告的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!