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

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

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

posted @ 2013-07-02 00:58  悠游天下  阅读(1910)  评论(0编辑  收藏  举报