string ls_pathname, ls_filename
integer li_value
li_value = GetFileOpenName("选择照片", &
+ ls_pathname, ls_filename, "图片文件","jpg File (*.jpg),*.jpg,bmp file(*.bmp),*.bmp,gif file(*.gif),*.gif")
IF li_value = 1 THEN
P_1.picturename=ls_pathname;
Elseif li_value=-1 then
MessageBox("选择照片","打开文件错误!")
End If
2、获取图片的二进制数据
//处理照片文件数据开始
string ls_photofile
integer li_filenum
integer li_loops
integer li_counter
blob lb_picture
long ll_filelen
blob ll_read
ls_photofile=p_1.picturename;
ll_filelen=filelength(ls_photofile)
li_filenum=fileopen(ls_photofile,streammode!,read!,lockread!)
//*fileread()函数不支持读取大于32k的文本,计算将使用fileread函数的次数 */
if ll_filelen>32765 then
li_loops=((ll_filelen - 1)/32765)+1
else
li_loops=1
end if
//读文件
for li_counter=1 to li_loops
fileread(li_filenum,ll_read)
lb_picture=lb_picture+ll_read
next
fileclose(li_filenum)
//显示图片
p_1.setpicture(lb_picture)
//处理照片文件结束
3、存入数据库
//存照片入数据库
updateblob t_teacher set pic=:lb_picture where code = :ls_code;
if sqlca.sqlcode<>0 then
messagebox("系统提示","更新数据错误",stopsign!,ok!)
return
end if
4、显示图片
blob lb_pic
string ls_code
ls_code="01007";
selectblob pic into :lb_pic from t_teacher where code=:ls_code;
if sqlca.sqlcode<>0 then
messagebox("系统提示","载入数据错误",stopsign!,ok!)
return
end if
setpicture(p_1,lb_pic)
-----------------------------------------------------------------------------------------------------------------------
用视频抓拍图片时,把图片保存到目录下,再显示在PB图像控件中,当抓拍第一张图片时,图像控件可以正常显示(用p_1.PictureName ='C:\pic.bmp'),再抓拍图片再显示时,p_1控件还是显示第一张图片。经过分析和跟踪,当显示第二次图像时,要在显示图片代码前加一句p_1.PictureName = ""就可以了。[清空路径]
代码实现:
p_1.PictureName = ""
p_1.PictureName ="c:\pic.bmp"
获取图片大小尺寸函数
// 函数: of_getpicturetype()