1. 程式人生 > >PB儲存圖片、讀取圖片、顯示圖片

PB儲存圖片、讀取圖片、顯示圖片

選擇要儲存的圖片

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

獲取圖片的二進位制資料

//處理照片檔案資料開始 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)

//處理照片檔案結束

存入資料庫

//存照片入資料庫 updateblob t_teacher set pic=:lb_picture where code = :ls_code;

if sqlca.sqlcode<>0 then

messagebox("系統提示","更新資料錯誤",stopsign!,ok!)

return

end if

讀取圖片

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)