在PB中存图片入数据库及显示图片
摘自:http://www.xicc.cn/User0/109/Show.asp?/_articleid/549.html
1、选择图片
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)