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)

-----------------------------------------------------------------------------------------------------------------------

用视频抓拍图片时,把图片保存到目录下,再显示在PB图像控件中,当抓拍第一张图片时,图像控件可以正常显示(用p_1.PictureName ='C:\pic.bmp'),再抓拍图片再显示时,p_1控件还是显示第一张图片。经过分析和跟踪,当显示第二次图像时,要在显示图片代码前加一句p_1.PictureName = ""就可以了。[清空路径]

代码实现:

p_1.PictureName = ""

p_1.PictureName ="c:\pic.bmp"

 

获取图片大小尺寸函数

//   函数:   of_getpicturetype()  

  //--------------------------------------------------------------------  
  //   描述:   获得图片文件的图像尺寸大小(支持GIF,JPG,BMP格式)  
  //--------------------------------------------------------------------  
  //   参数:    
  //value         blob ab_FileNameblob           图片文件 blob  
  //reference        string  aS_Filetype           图片文件类型  jpg png bmp gif
  //--------------------------------------------------------------------  
  //   返回值:     int  成功为1 失败为 0
  //--------------------------------------------------------------------      
  //   GIF目前主要有两种类型  
  //   1.   标识为GIF87a,   只是用来存储单幅静止图像  
  //   2.   标识为GIF89a,   可以同时存储若干幅静止图像并进而形成连续的动画   
  //   GIF   文件格式判断   
   //   JPEG文件格式  
  //   前   3   个字节为标识:   0xFF,0xD8,0xFF  
    //   BMP文件格式  
  //   前两个字节是标识:标识可能有很多种  
// PNG文件格式  
  //   前   8   个字节为标识:   ox89 ox50 ox4E ox47 ox0D ox0A ox1A ox0A
  If   long(BlobMid(ab_FileNameblob,1,4))   = 944130375  Then  
  as_filetype = 'gif'
  Return   1  
ElseIf   long(BlobMid(ab_FileNameblob,7,4)) = 1179207242 Then  
as_filetype = 'jpg'
Return   1  
  ElseIf   integer(BlobMid(ab_FileNameblob,1,4))   =  19778 Then  
  as_filetype = 'bmp'
  Return   1  
  ElseIf   long(BlobMid(ab_FileNameblob,1,4))   =  1196314761 and  long(BlobMid(ab_FileNameblob,5,4))   =  169478669   Then  
as_filetype = 'png'
Return   1  
  Else   
  Return   0  
  End   If  

说明:该函数用于识别图片格式。大家可以借鉴,用于识别图片大小等等信息。

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值