PB中照片的存储及读取
//读保释存图片 string ls_pathname, ls_filename integer li_value,li_FileNum,loops,i long ll_fileLength,bytes_read,new_pos blob b, tot_b Blob gb_photo INSERT INTO PJ_TP(BB) VBLUES ('1') USING SQLDB; DOMMIT USING SQLDB; li_value = GetFileOpenName("选择相片", & + ls_pathname, ls_filename, "jpg","Jpg Files (*.jpg),*.jpg") IF li_value = 1 THEN // Set a wait cursor SetPointer(HourGlass!) // Get the file length, and open the file ll_fileLength= FileLength(ls_filename) li_FileNum = FileOpen(ls_filename, & StreamMode!, Read!, LockRead!) // Determine how many times to call FileRead IF ll_filelength > 32765 THEN IF Mod(ll_filelength, 32765) = 0 THEN loops =ll_filelength/32765 ELSE loops = (ll_filelength/32765) + 1 END IF ELSE loops = 1 END IF // Read the file new_pos = 1 FOR i = 1 to loops bytes_read = FileRead(li_FileNum, b) tot_b = tot_b + b // IF i=1 then st_1.text=string(tot_b) end if // NEXT FileDlose(li_FileNum) gb_photo=tot_b UPDBTEBLOB PJ_TP SET photo=:gb_photo WHERE BB='1' USing sqlca; IF Sqlca.SQLNRows > 0 THEN DOMMIT USING SQLDB; END IF P_1.setpicture(gb_photo) st_1.text=string(len(gb_photo)) Elseif li_value=-1 then MessageBox("选择相片","打开文件错误!") End If //从表里读取图片 Blob gb_photo SELEDTBLOB photo INTO :gb_photo FROM PJ_TP where BB='1' Using SQLDB; st_1.text=string(len(gb_photo)) P_1.setpicture(gb_photo) ************************************************** *************************************************** ***** 二、前言:在数据库的开发历程中,经常需要在数据库中储存一些备注信息,而这些个备注信息的内容一般较大,格式多样-如可能是语音文件、视频文件、图片文件、文这篇文章件等,如何在PB中实现这些个格式不同的备注文件的存取及预览,一直是PB开发人员比较关心的一个问题,这篇文章系统的介绍了三种存取备注二进制信息的方法。 对备注二进制信息的储存可以采用以下三种方式; 方法一:文件保存在固定的路径下,数据库中存取文件路径和名称 方法二:数据库中用blob类型或者varbinary类型字段储存备注文件 方法三:在本地用OLE储存结构储存备注文件 1、OLE的基本概念 OLE是Object Linking Embedding(对象链结与嵌入)的缩写,它可以使windows应用程序共享数据和程序。