pb 通过 Database Binary/Text Large Object显示图片

xueru9999 2009-05-14 07:17:33
sqlserver2000+pb10.5
我有一个表存放照片的 字段是 用户编号,照片(blob)

里面的 key clause 我不知道怎么写,如果写成 用户编号 = :bh
那么在retrieve的时候就会报错 提示 = 附近有错误;
无奈我想先测试一下看看能不能看到图片就把 key clause 写成 用户编号 = '00011'
但是建立好了 blob 进行retreve 的时候并看不到图片啊,是不是我哪里做的不对啊

我原来想了一个其他的办法就是用selectblob 将数据读出来写成文件,但是以前数据库中存在的照片是通过vf9的ole直接存入数据库的。我现在写出来的文件有大小,看是看不到图片内容,请问这个应该怎么处理啊?
...全文
463 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fm20027 2009-05-16
  • 打赏
  • 举报
回复
一楼的方法比较好用。照片或图片存取可以直接用语句selectbolb和updateblob语句完成。
从数据库表中取照片:
selectblob photo
into :lb_blob
from emp_photo
where identify_no = :is_parm;
放到p_1: p_1.setpicture(lb_blob)
将照片存入数据库:

变量说明省略

li_succ = getfileopenname('人员照片',ls_path,ls_filename,"照片文件 (*.bmp;*.gif;*.jpg;*.jpeg),*.bmp;*.gif;*.jpg;*.jpeg")

if li_succ <> 1 then return

setpointer(hourglass!)

//得到文件的长度---这里是关键,每次读取文件不能超过32K
ll_filelen = filelength(ls_path)

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

//计算读文件的次数,不能一次读大于32K的数据
if ll_filelen > 32766 then
if mod(ll_filelen,32766)=0 then
li_loops = ll_filelen/32766
else
li_loops = (ll_filelen/32766) + 1
end if
else
li_loops = 1
end if

for li_counter = 1 to li_loops

ll_bytes_read = fileread(li_filenum,lb_our_blob)
lb_tot_b = lb_tot_b + lb_our_blob
ll_new_pos = ll_new_pos + ll_bytes_read
fileseek(li_filenum,ll_new_pos,frombeginning!)
next

fileclose(li_filenum)
//图片可以显示在P_1了
p_1.visible = true
li_succ = p_1.setpicture(lb_tot_b)
//开始往数据库里存
sqlca.autocommit = true

//oracle可以这样写来判断是否存在记录,一般也可以写成select count(*) into :li from table_name where ...
//假设存放照片的表只有两个列,一列是人员身份证号(key) not null,一列是照片(blob数据类型)null
SELECT identify_no INTO :ls_id
FROM emp_photo
WHERE identify_no = :is_parm
AND ROWNUM < 2
USING SQLCA;
//如果记录不存在,则先加上一条
IF SQLCA.SQLNRows = 0 THEN
insert into emp_photo (identify_no)
values(:is_parm);
end if

//存储指定的照片
updateblob emp_photo
set photo = :lb_tot_b
where identify_no = :is_parm
using sqlca;


if sqlca.sqlcode = 0 then
commit;
messagebox('照片存库','存储成功!')
end if

sqlca.autocommit = false
xueru9999 2009-05-15
  • 打赏
  • 举报
回复
照片文件是通过 vf9的ole控件直接写入的,现在我要用pb把图片取出来显示,
我是通过 selectblob 照片 from t_zp where id=:id;
写入 id.dmp 文件 ,用任何看图工具都打不开或者看不到内容。
用记事本打开我写的文件会看到里面写的内容开头是
0 " ?uisual FoxPro Paint.Picture PBrush 圊 BM条 6 ( |
难道vf9的ole处理图片会有什么变化吗?
xueru9999 2009-05-15
  • 打赏
  • 举报
回复
gif,jpg和bmp三种
newease 2009-05-15
  • 打赏
  • 举报
回复
你用ole存入图片是什么格式的bmp,jpeg ?

p_1控件只支持 gif/wmf/bmp/jpeg/rle格式
xueru9999 2009-05-15
  • 打赏
  • 举报
回复
自己顶一下
xueru9999 2009-05-15
  • 打赏
  • 举报
回复
各位高手啊,使用p_1.SetPicture(blob) 直接提示

not a jpeg file starts with 0xd0 0xcf
难道用vf9 的ole 控件存入的图片会改变吗?
singsongs 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 eviler 的回复:]
你试试 在窗口上方一个 picture 控件 p_1,独处blob后 使用 p_1.SetPicture(blob)
[/Quote]这个办法比较简单易用。
newease 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 eviler 的回复:]
你试试 在窗口上方一个 picture 控件 p_1,独处blob后 使用 p_1.SetPicture(blob)
[/Quote]

我一般采用1楼的这种方式,如果需要我可以把图片存储、读取的示例发至邮箱
WorldMobile 2009-05-15
  • 打赏
  • 举报
回复
另一种方法

自己做成ole

存入:
int li_filenum,li_loops,li_counter
long ll_filelen,ll_bytes_read,ll_new_pos
blob lb_our_blob,lb_tot_b
string ls_id


//得到文件的长度
ll_filelen = filelength(is_filename)

li_filenum = fileopen(is_filename,streammode!,read!,lockread!)
//计算读文件的次数,不能一次读大于32K的数据
if ll_filelen > 32766 then
if mod(ll_filelen,32766)=0 then
li_loops = ll_filelen/32766
else
li_loops = (ll_filelen/32766) + 1
end if
else
li_loops = 1
end if
//读文件
for li_counter = 1 to li_loops
ll_bytes_read = fileread(li_filenum,lb_our_blob)
lb_tot_b = lb_tot_b + lb_our_blob
ll_new_pos = ll_new_pos + ll_bytes_read
fileseek(li_filenum,ll_new_pos,frombeginning!)
next

fileclose(li_filenum)

select e_id into :ls_id
from employee_photo
where e_id = :is_parm
using sqlca;

if sqlca.sqlcode <> 0 then
insert into employee_photo
(e_id) values(:is_parm);
commit;
end if

//sqlca.autocommit = true
//将照片放入图片控件中
p_2.SetPicture(lb_tot_b)
//存储指定的照片
updateblob employee_photo
set photo = :lb_tot_b
where e_id = :is_parm
using sqlca;

if sqlca.sqlcode = 0 then
commit;
sle_1.text = "照片存储成功(" + is_parm + ")"
else
rollback;
sle_1.text = "照片未存入(" + is_parm + ")"
end if

检索:

blob lb_blob_var

selectblob photo
into :lb_blob_var
from employee_photo
where e_id = :is_parm
using sqlca;

rollback;

if isnull(lb_blob_var) then
lb_blob_var = blob(" ")
end if

setpicture(p_1,lb_blob_var)
WorldMobile 2009-05-15
  • 打赏
  • 举报
回复
用OLE实现


存储图片

li_fh = GetFileOpenName("选择图片文件",&
ls_filename, ls_path,"aaaaa","图片文件,*.bmp;*.jpg;*.jpeg;*.gif,")
IF li_fh = 0 THEN return
if ole_1.insertfile(ls_filename) = -1 then return
Emp_id_pic = ole_1.objectdata

//存储BLOB
UPDATEBLOB djfz_sfcf_picture
SET zpicture = :Emp_id_pic
WHERE zpk = :li_id;

IF sqlca.sqlnrows > 0 THEN
COMMIT;
messagebox('系统提示','图片存储成功!')
else
rollback;
messagebox('错误提示','图片存储失败!',stopsign!)
END IF

读取图片
SELECTBLOB zpicture
INTO :Emp_id_pic
FROM djfz_sfcf_picture
WHERE zpk = :li_id;
if isnull(Emp_id_pic) then
messagebox('系统提示','对不起,此记录暂时没有图片!')
return
end if
ole_1.objectdata = Emp_id_pic
ole_1.activate(offsite!)
eviler 2009-05-14
  • 打赏
  • 举报
回复
你试试 在窗口上方一个 picture 控件 p_1,独处blob后 使用 p_1.SetPicture(blob)

609

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧