图片存取的完整操作过程

Integer li_rtn = 0
String ls_pathname, ls_filename
String ls_ext = "JPG"
String ls_filter = "JPG文件, *.JPG,图片文件(*.BMP), *.BMP"
//确定要写入的文件名
li_rtn = GetFileOpenName("请选择一张图片", ls_pathname, ls_filename, ls_ext, ls_filter)
if li_rtn = 1 then
    Long ll_filelen = 0
        //文件长度
    ll_filelen = FileLength(ls_pathname)
        //打开文件
    li_rtn = FileOpen(ls_pathname, StreamMode!)
    if li_rtn <> -1 then
        Blob lblb_pic, lblb_temp
        Int i = 0
        do until ll_filelen <= 0
                        //读取文件
            FileRead(li_rtn, lblb_temp)
            lblb_pic = lblb_pic + lblb_temp
            ll_filelen -= 32765
            i ++
                        //定位指针
            FileSeek(li_rtn, 32765 * i + 1)
        loop
                //关闭文件
        FileClose(li_rtn)
        iblb_pic = lblb_pic
        p_1.SetPicture(iblb_pic)
    end if
   //还可以保存图片的路径,该字段为string类型在找到图片后直接用p_1.picturename = ls_filename
   //保存ls_filename即可
end if

点击商品时显示对应的图片:
sql sever对应的字段类型为image
blob lblb_pic
lblb_pic = blob("")

SelectBlob photo Into :lblb_pic
    From goods
    Where goodscode = :is_goodscode;
sqlca.AutoCommit = false

//数据库中没有对应的图片要有一个默认的图片
if IsNULL(lblb_pic) or lblb_pic = blob("") then
    int li_rtn = 0
    li_rtn = FileOpen("./PIC/Question.bmp", StreamMode!)
    if li_rtn <> -1 then
        blob lblb_temp
        FileRead(li_rtn, lblb_temp)
        FileClose(li_rtn)
        lblb_pic = lblb_temp
       
    end if
end if
//确定对应的图片
//可以直接写成p_1.picturename = "./PIC/Question.bmp"
p_1.SetPicture(lblb_pic)
//更新图片
UPDATEBLOB Goods
Set Photo = :iblb_pic
Where goodscode = :is_goodscode;

你可能感兴趣的:(图片存取的完整操作过程)