主题
:将数据库中以
image
类型保存的图片另存为
jpg
文件,并将其路径存入数据库
整理人 : icefireleaf
整理人 : icefireleaf
整理时间:
2006-12-19
备注
:该代码在
PB8.0
下编写,
FileWrite
函数一次仅可写
32,766
字节,该代码中限制每次写
30,000
字节
//----------------------------------------------------------------//
long ll_filelen,ll_j
blob lbb_photo,lbb_subfile
//
string ls_docname, ls_named,ls_stk_no
integer li_fileno
//
int li_i,li_times,li_value
int li_balance
int li_limit=30000//
定义读取图片限制
long ll_start,ll_end
//
for ll_j=1 to dw_1.rowcount()//dw_1
中显示所有需要转换的记录
ls_stk_no=dw_1.object.stk_no[ll_j]
//read photo from database
SELECTBLOB catalog_picture
INTO : lbb_photo
FROM ORmaster
where stk_no=:ls_stk_no using sqlca;
//"//server/mcphoto/old/"
为转换后的图片在服务器上的存放路径
ls_docname="//server/mcphoto/old/" + ls_stk_no + ".jpg"
li_fileno = FileOpen(ls_docname,STREAMMODE!,Write!, Shared!, Append!)
//----------------------------------------------------------------------------//
//write photo as a file
ll_filelen = Len(lbb_photo)
li_balance=mod(ll_filelen,li_limit)
li_times=(ll_filelen - li_balance)/li_limit
for li_i=1 to li_times
ll_start=(li_i - 1)*li_limit + 1
ll_end=li_limit
lbb_subfile=blobmid(lbb_photo,ll_start,ll_end)
filewrite(li_fileno,lbb_subfile)
next
if li_balance>0 then
ll_start=li_times*li_limit + 1
ll_end=li_balance
lbb_subfile=blobmid(lbb_photo,ll_start,ll_end)
filewrite(li_fileno,lbb_subfile)
end if
//save the path of photo
update ormaster_sub set picture_path=:ls_docname where stk_no=:ls_stk_no;
st_1.text=string(round(ll_j/dw_1.rowcount(),4)*100) + "%"//
显示转换进度
next
if sqlca.sqlcode=0 then
commit;
messagebox(gs_sysmess,"
图片另存成功
")//gs_sysmess
为定义的
messagebox
对话框的标题
end if