将数据库中以image类型保存的图片另存为jpg文件,并将其路径存入数据库

这篇博客讲述了如何在PB8.0环境下,从数据库中读取以image类型存储的图片,将其另存为jpg文件,并将新图片的路径保存回数据库的过程。通过循环遍历记录,使用BlobMid和FileWrite函数分段写入文件,最后更新图片路径到数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
主题     :将数据库中以 image 类型保存的图片另存为 jpg 文件,并将其路径存入数据库
整理人   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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值