在MS Access Image控件中显示/加载URL中的图片 [英] Show/Load pictures from URL in MS Access Image control

查看:167
本文介绍了在MS Access Image控件中显示/加载URL中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问这个问题并要回答,因为我认为我们很多人以前都曾问过这种情况,并为此感到挣扎.希望这对将来的读者和开发人员有所帮助.

I'm asking this question and going to answer it, as I think many of us asked and struggled with this situation before. Hope this helps future readers and developers.

如何在MS Access Image Control中显示/加载超链接/网页图片?

Me.ImageControl.Picture = "https://example.com/SamplePicture.png" 'Throws an error but
Me.ImageControl.Picture = "C:\SamplePicture.png" ' Works

问题:我想使用图片"控件并显示来自网络的图片.

Question: I would like to use the Image control and show pictures from the web.


请改善我的答案或添加您的方法.


Plese do improve my answer and or add your methods.

对于那些希望就自己的github项目回答问题进行辩论的人 垃圾邮件?还是没有垃圾邮件?

for those who wish to debate about answering with own github project Spam? or no spam?

范围太广?有些问题确实太广泛了,无法回答或取决于用户情况.这个问题是否太广泛了?我不知道.问题是如何将在线图片加载到图像控件中?下面,您将从每个人的方法中学到不错的方法.包括我的.

Too broad? Some questions are truely too broad to answer or depend on the user situation. Whether this question is too broad? I'm not sure. The question is how do I load online picture into an image control? below you will read nice methods from everyone's approach. Including mine.

我想在SO中注册该问题,因为大多数Google搜索图片和超链接都是非SO结果,并且大多数都不像SO那样可读.

I wanted to register this question in SO because most google search about image and hyperlinks are non SO results and most aren't nice to read like SO.

推荐答案

MS Access Image控件非常适合加载本地文件,但是如果将图片另存为网址,则将很难显示它们.如果尝试将任何url分配给Image.picture属性,则会收到"Microsoft cannot open the file"错误.

MS Access Image control is great for loading local files but if you are saving your pictures as web-url, you will have hard time showing them. If you try to assign any url to the Image.picture property, you will receive "Microsoft cannot open the file" error.

有一些解决方法.

  1. 下载并保存图片并加载到图像控件中
  2. 使用网络浏览器控件
  3. 购买第三方控件
  4. (我不知道的任何其他方法)

以上所有方法都可以使用,但是它们要么带有额外的代码,要么在本地系统上占用了过多的空间. IE.下载并加载图像将使您陷入困境,并在部分显示完图片后清理混乱.

All of above will work but they come either with extra code or too much footprints on the local system. I.e. Downloading and loading image would leave you with downlod and cleaning up the mess after finish showing pictures part.

Web浏览器控件需要一些HTML包装器,因此您可以进行一些基本的调整.有些人会购买第三方控件,但我们大多数人都不想安装任何Activx控件.尤其是如果您必须将访问文件发送给其他人.

Web-browser control requires some HTML wrappers so you can do some basic sizing. Some would buy third-party controls but most of us don't want to install any activx control. Especially if you have to ship your access file to someone else.

我的方法 使用.NET,我正在为VBA环境开发与应用程序无关的插件组件的集合(请参阅我的

My approach Using .NET I'm developing a collection of application independent plug-in-components for VBA environment (see my GitHub). Hoping to expand and ease some of daily used tasks in VBA.

最近,我编写了一个函数,该函数可以读取超链接并为MS Access Image控件返回PictureData.这样一来,您就可以从网上加载任何图片并轻松显示. 下载示例

Recently I wrote a function that can read a hyperlink and return PictureData for MS Access Image control. This allows you to load any pictures from online and show it without too much hassle. Download sample

以下是有关dll函数的一些信息.

Here is some information about the dll function.

  'Download the sample database from my github and see how to plug-in the dll.
  'Dll function fromt the dll. If you want to write your own vba wrapper
  'PictureFromUrl(
    string URL,             :  Image url. web url or local path
    bool ShowError = false, : Show error notification when url cannot be loaded
    long sender = 0         : Sender HWND, not used now.
    )

在VBA中.

  'VBA Wrapper (used for simplicity)
  'ImageControlGetImage(ImagePath as string, optional ShowError=true)

'Loading web url
Private Sub Command147_Click()
    Dim WebPicture As String
    WebPicture = "https://avatars2.githubusercontent.com/u/1001697?s=460&v=4"

    Me.Image113.PictureData = gDll.ImageControlGetImage(WebPicture, ShowError:=True)
End Sub

.

'    
'Same function can be used to load local files
'
Private Sub Command149_Click()
    Dim WebPicture As String
    WebPicture = "F:\Projects\VBA_DLL\dialogboxgreen.png"

    Me.Image113.PictureData = gDll.ImageControlGetImage(WebPicture, ShowError:=True)

End Sub

如果您想从表格中读取网址

If you would like to read urls from your table

而不是使用control source属性,而是使用表单中的on current事件来加载图片.

instead using the control source property, use the on current event in your form to load the pictures.

Private Sub Form_Current()
  'Load pictures 
    Me.Image8.PictureData = gDll.ImageControlGetImage([url], True)
End Sub

这篇关于在MS Access Image控件中显示/加载URL中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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