Private Sub DownloadButton_Click()
Dim nret As Long
Dim cnt1 As Long
Dim picsize As Long
Dim FileName
Dim FileNum
On Error GoTo SampleError
If CamFolderList.ListIndex = -1 Then
MsgBox "No picture selected"
Exit Sub
End If
'Set current picture
ZoomScrl.Rye1.propCurrentPicture(nCurrentCamera) = CamFolderList.ListIndex + 1
'Get current picture file size
picsize = ZoomScrl.Rye1.propPicSize(nCurrentCamera)
ReDim Picbuff(picsize) As Byte
'Get current picture file name
FileName = ZoomScrl.Rye1.propFileName(nCurrentCamera)
ProgressForm.Caption = FileName
PictureForm.Caption = FileName
ProgressForm.Show 0, Me
'Get picture from camera
ZoomScrl.Rye1.GetPicture nCurrentCamera, picsize, Picbuff
SampleError:
If Err.Number <> 0 Then
MsgBox Err.Number
Else
PictureForm.Caption = FileName
ProgressForm.Message = "Saving..."
'Get file access ID
FileNum = FreeFile
'Create file
Open "Picture.jpg" For Random As FileNum Len = 1
'Write index picture data
For cnt1 = 1 To picsize
Put FileNum, cnt1, Picbuff(cnt1 - 1)
Next
'Close index file
Close FileNum
Unload ProgressForm
Set PictureForm.PicCtrl.Picture = LoadPicture("Picture.jpg")
PictureForm.Show 0, Me
End If
End Sub
Dim nret As Long
Dim cnt1 As Long
Dim picsize As Long
Dim FileName
Dim FileNum
On Error GoTo SampleError
If CamFolderList.ListIndex = -1 Then
MsgBox "No picture selected"
Exit Sub
End If
'Set current picture
ZoomScrl.Rye1.propCurrentPicture(nCurrentCamera) = CamFolderList.ListIndex + 1
'Get current picture file size
picsize = ZoomScrl.Rye1.propPicSize(nCurrentCamera)
ReDim Picbuff(picsize) As Byte
'Get current picture file name
FileName = ZoomScrl.Rye1.propFileName(nCurrentCamera)
ProgressForm.Caption = FileName
PictureForm.Caption = FileName
ProgressForm.Show 0, Me
'Get picture from camera
ZoomScrl.Rye1.GetPicture nCurrentCamera, picsize, Picbuff
SampleError:
If Err.Number <> 0 Then
MsgBox Err.Number
Else
PictureForm.Caption = FileName
ProgressForm.Message = "Saving..."
'Get file access ID
FileNum = FreeFile
'Create file
Open "Picture.jpg" For Random As FileNum Len = 1
'Write index picture data
For cnt1 = 1 To picsize
Put FileNum, cnt1, Picbuff(cnt1 - 1)
Next
'Close index file
Close FileNum
Unload ProgressForm
Set PictureForm.PicCtrl.Picture = LoadPicture("Picture.jpg")
PictureForm.Show 0, Me
End If
End Sub
Dim cnt1 As Long
Dim picsize As Long
Dim FileName
Dim FileNum{On Error Goto VB的错误捕获机制,表示如果运行出错跳转到SampleError部分。类似Delphi的raise,可以用Try...Except...End代替。}
On Error GoTo SampleError{如果没有选择图片则提示'No picture selected',并退出过程。类似Delphi的
if Combobox1.ItemIndex = -1 then
begin
showmessage('No picture selected');
exit;
end;}
If CamFolderList.ListIndex = -1 Then
MsgBox "No picture selected"
Exit Sub
End If{下面有英文注视我就不用说了。大意是把相机设置当前图片,并将图片的大小存入picsize}
'Set current picture
ZoomScrl.Rye1.propCurrentPicture(nCurrentCamera) = CamFolderList.ListIndex + 1
'Get current picture file size
picsize = ZoomScrl.Rye1.propPicSize(nCurrentCamera){ReDim 是重定义变量类型及长度}
ReDim Picbuff(picsize) As Byte
{从相机中获得当前图片的文件名} 'Get current picture file name
FileName = ZoomScrl.Rye1.propFileName(nCurrentCamera){读取照片进度的窗体标题设为当前照片的文件名} ProgressForm.Caption = FileName{显示照片的窗体标题设为当前照片的文件名}
PictureForm.Caption = FileName{显示读取照片的进度条窗体}
ProgressForm.Show 0, Me{下面是从相机中读出照片,nCurrentCamera应该是当前相机,picsize是大小,Picbuff照片缓冲}
'Get picture from camera
ZoomScrl.Rye1.GetPicture nCurrentCamera, picsize, Picbuff
{以下就是运行错误时执行的语句。}SampleError:{如果错误代码不为零则显示错误代码号} If Err.Number <> 0 Then
MsgBox Err.Number
{否则保存照片,Open "Picture.jpg" For Random As FileNum Len = 1是建立随机文件Picture.jpg,宽度为1} Else
PictureForm.Caption = FileName
ProgressForm.Message = "Saving..."
'Get file access ID
FileNum = FreeFile
'Create file
Open "Picture.jpg" For Random As FileNum Len = 1
'Write index picture data
{For...Next就是Delphi的For循环} For cnt1 = 1 To picsize
Put FileNum, cnt1, Picbuff(cnt1 - 1)
Next
'Close index file
Close FileNum
Unload ProgressForm{在图片框里显示保存的照片,相当于Delphi里的LoadFromFile} Set PictureForm.PicCtrl.Picture = LoadPicture("Picture.jpg"){显示照片窗体} PictureForm.Show 0, Me
End If
End Sub