关于pic_Box控件 以及loadPicture函数的问题

TonyLau1113 2006-07-07 11:34:08
我想把下面验证码图片显示到VB里的picturebox 控件中

先下载图片并存成适当格式,然后用loadPicture方法显示在控件中
但是每次程序都死掉,应该是控件的问题

有兴趣的可以试一下!

图片地址:http://www.hn110.cn/Login/getcode.asp
随便下载一个都会出现该问题!

请问是控件问题还是图片有什么特殊设置呢?
有没有办法解决呢?

...全文
279 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
6742 2006-07-22
  • 打赏
  • 举报
回复
WebBrowser1.Navigate “http://www.hn110.cn/Login/getcode.asp ”可以打开,

不过要说明的是你这个GIF文件,就是PHOTOSHOP也打不开的,说是那种动画格式,也可以看到一帧,可它却是说不能解析该文件,如WallesCai(沧海明月一度,西风残阳无悔.) 所说“估计是比较新的GIF格式”了。
6742 2006-07-22
  • 打赏
  • 举报
回复
用WebBrowser1.Navigate http://www.hn110.cn/Login/getcode.asp 应该没有问题
一笑拔剑 2006-07-21
  • 打赏
  • 举报
回复
gif用pic好像不行吧
ie可以打开你试下用webbrower
熊孩子开学喽 2006-07-21
  • 打赏
  • 举报
回复
看过了,这是GIF的格式问题.
估计是比较新的GIF格式,VB不认.

你将该图片保存到本地硬盘,再用程序去loadpicture也打不开.
说明是图片格式不认的原因
TonyLau1113 2006-07-17
  • 打赏
  • 举报
回复
下载绝对正常的!

源文件用.htm格式打开都可以正常看到图片

但是取不到象素值
只有用pic_box

一loadpic就死掉!应该是控件的问题

有没有人知道其他好点的可以取到象素值的控件啊!?
一笑拔剑 2006-07-17
  • 打赏
  • 举报
回复
你先看看下载正常不?
如果下载正常的话很可能是你循环出问题了
一笑拔剑 2006-07-17
  • 打赏
  • 举报
回复
对付验证码?
TonyLau1113 2006-07-17
  • 打赏
  • 举报
回复
晕,没有人遇到过吗 !?
TonyLau1113 2006-07-07
  • 打赏
  • 举报
回复
下面是一个测试小工具源码,有兴趣的可以帮忙看看。谢谢

窗体:一个picBox,一个txt,一个command
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szUrl As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim szpath As String

Private Sub Command1_Click()

Dim strUrl As String
Dim strImage As String
Dim szImageName As String
Dim count As Long
Dim szFileName As String
Dim isDownSuc As Boolean
Dim J As Long
strUrl = Trim(Text1.Text)

szFileName = Mid(strUrl, 8)
szFileName = Left(szFileName, InStr(1, szFileName, "/") - 1)

strImage = App.Path & "\temp\" & szFileName

If Dir(App.Path & "\temp", vbDirectory) = "" Then
MkDir App.Path & "\temp"
End If

Retry:
'//取图片的API
URLDownloadToFile 0, strUrl, strImage, 0, 0
Sleep 500
DoEvents
'//重试3次,不成功则不显示
If Dir(strImage) = "" Then
If J >= 5 Then
J = 0
isDownSuc = False
Else
J = J + 1
DoEvents
GoTo Retry
End If
Else
isDownSuc = True
End If
'//判断图片类型
szImageName = strImage & "." & ProcessImageFile(strImage)
On Error Resume Next
'//重命名图片文件
Name strImage As szImageName
'//用picbox显示图片
Picture1.Picture = LoadPicture(szImageName)
DoEvents
Sleep 500
Err.Clear

End Sub

moudle中用来判断图片类型的函数:

Public Function ProcessImageFile(ImageFileName As String, Optional CharsCount As Long = 0) As String

Dim FileNumber As Integer
Dim strData As String
Dim alngBits() As Long
Dim I&, J&, K&, M&, lBit&
Dim fs, a
Dim strTemp As String
Dim lWidth&, lHeight&
Dim vntSplit As Variant
Dim bytTemp As Byte
Dim abtBit(1 To 5) As Byte
Dim strValue As String
Dim strExt As String
Dim strResult As String
Dim vntSp

On Error Resume Next
FileNumber = FreeFile ' 取得未使用的文件号。
Open ImageFileName For Binary Access Read As #FileNumber ' 创建文件名。
Get #FileNumber, , abtBit ' 输出文本至文件中。
Close #FileNumber ' 关闭文件。
If (abtBit(1) = &H23 And abtBit(2) = &H64 And abtBit(3) = &H65) Then strExt = "xbm"
If (abtBit(1) = &H47 And abtBit(2) = &H49 And abtBit(3) = &H46) Then strExt = "gif"
If (abtBit(1) = &H89 And abtBit(2) = &H50 And abtBit(3) = &H4E) Then strExt = "png"
If (abtBit(1) = &HFF And abtBit(2) = &HD8 And abtBit(3) = &HFF) Then strExt = "jpg"
If (abtBit(1) = &H42 And abtBit(2) = &H4D) Then strExt = "bmp"
Err.Clear
ProcessImageFile = strExt
End Function
TonyLau1113 2006-07-07
  • 打赏
  • 举报
回复
晕,怎么没人呀!

自己顶一下!

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧