问题描述
在Access 2013报表中,我通过链接表连接到Oracle DB视图.一个视图字段的类型为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.
我在Internet上检查了有关此(非常古老)主题的更多文档,但找不到有关此特定问题的任何信息.
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控件
- 将图像保存到磁盘中的临时文件夹中,并将图像控制源设置为其位置
- 使用Web浏览器控件,并使用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
然后,我们可以使用Web浏览器控件,然后将包含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
是您的Web浏览器控件的名称,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附带的控件.否则,您将获得Internet Explorer的过时版本,带有无法删除的3d边框.
- 将Web浏览器控件的控件源设置为
="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报告时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!