PB中保存图片

 //****************************************************************

“选择”按钮代码:

lb_image = gf_open_pic(p_1,lb_image)

p_1.setpicture(lb_image)

//***************************************************************

“清除”按钮代码:

p_1.picturename = ''

p_1.picturename = ''//(需要两次)

setnull(lb_image)



//***************************************************************

函数gf_open_pic:

//
//Add by Jeffrey Jiang on 2001.11.13

//选择图片

/

//Modfiy by Jeffrey Jiang on 2001.11.15

//当图片字节大于32765时,循环读图片

/



integer li_file,li_ret,loops,i

string ls_file,ls_path

blob lb_small
long flen,bytes_read,new_pos



//search the file

li_ret = getfileopenname("选择图片文件",ls_path,ls_file, &

"BMP","图片文件(*.BMP),*.BMP")

if li_ret = 1 then

p_1.picturename = ''

p_1.picturename = ''

setnull(lb_image)

if li_file <> -1 then

// Set a wait cursor

setpointer(hourglass!)
flen = filelength(ls_file)

li_file = fileopen(ls_path,streammode!,read!,lockread!)

// Determine how many times to call FileRead

if flen > 32765 then

if mod(flen,32765)=0 then

loops = flen/32765

else

loops = (flen/32765) + 1

end if

else

loops = 1

end if

// Read the file
new_pos = 1

for i = 1 to loops

bytes_read = fileread(li_file,lb_small)

if i = 1 then

lb_image = lb_small

else

lb_image = lb_image + lb_small

end if

next

// close the file

fileclose(li_file)

end if
end if

return lb_image



//***************************************************************

保存按钮代码:

UPDATEBLOB "person" SET "person"."PHOTO" = :lb_image WHERE "person"."C_ID" = :ls_c_id USING SQLCA;

IF sqlcadoor.SQLNRows > 0 THEN

commit using sqlca;

END IF



//***************************************************************

显示图片:

lb_image = f_select_pic(ls_c_id)

p_1.setpicture(lb_image)



//***************************************************************

f_select_pic函数:

blob lb_image

setnull(lb_image)

selectblob "person"."PHOTO" into:lb_image from "person" where "person"."C_ID"=:ls_c_id using sqlca;

return lb_image



环境:PB65

数据库:sql anywhere 5.5


//数据库的字段根据自己的需要更改!!!!!

//*************************************************************



//*****************************************************************************



有人问到,如何清除数据库中的图片而不删除该条记录,操作如下:



保存图片到数据库要用UPDATEBLOB:

UPDATEBLOB "M" SET "M"."PHOTO" = :ib_image WHERE "M"."C_ID" = :ls_c_id ;
只删除图片而不删除记录要用UPDATE:

UPDATE "M" SET "M"."PHOTO" = null WHERE "M"."C_ID" = :ls_c_id ;

(数据库字段根据自己的做更改!)



之前提供的gf_open_pic()函数说明:

由于PowerBuilder提供的fileread()函数每次只能读出字节小于32765的图片,当图片大于32765时,我提供的gf_open_pic()函数循环读图片,传入两个参数p_1(picture),lb_image(blob)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值