在PB中存图片入数据库及显示图片

在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)

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值