如果找不到图片,则加载默认图像 [英] default image to be load if picture not found

查看:132
本文介绍了如果找不到图片,则加载默认图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在改变图片,因为选择了组合框。图片名称按组合框中的索引保存。我想要显示一个defaul picturt并且在文件夹/来源中找不到图片。



你能协助吗。



以下是我用来上传图片的编码vb6



Picture2.Picture = LoadPicture(App.Path&\&Combo1。文本&.jpg)

I am changing picture as combobox is selected. Picture name is saved as per index in combobox. I want to display a defaul picturt and picture is not found in folder / source.

Can you please assist.

Below is the coding I am using to upload the picture in vb6

Picture2.Picture = LoadPicture(App.Path & "\" & Combo1.Text & ".jpg")

推荐答案

我认为,如果你这样做,如果没有要加载的图片,你的系统会抛出一个Exeption。在这种情况下,您只需捕获Exeption并将Picture2.Picture设置为您喜欢的Default-Picture ...
I think, if you do it like this, your System throws an Exeption if there is no Picture to be loaded. In this case you only have to catch the Exeption and set the Picture2.Picture to your favourized Default-Picture ...


您好,



查看 FileSystemObject [ ^ ]在脚本运行时对象(SCRRUN.DLL)中找到。



这将为您提供检查图像文件是否存在的方法,然后设置默认图像(如果不存在)。



设置项目后参考脚本运行时(参见上面的链接),这样的东西应该是你要找的东西:



Hi,

Have a look at the FileSystemObject[^] found in the scripting runtime object (SCRRUN.DLL).

This will provide you the means to check if the image file exists, and then set your default image if it does not.

After you've setup your project reference to the scripting runtime(see the link above), something like this should be what you're looking for:

Dim oFso As New Scripting.FileSystemObject

If(oFso.FileExists(App.Path & "\" & Combo1.Text & ".jpg") Then
    Picture2.Picture = LoadPicture(App.Path & "\" & Combo1.Text & ".jpg") 
Else
    Picture2.Picture = LoadPicture(App.Path & "\defaultImage.jpg") 
End If





...希望它有所帮助。



... hope it helps.


这篇关于如果找不到图片,则加载默认图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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