打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
delphi 从数据库中批量导出图片

delphi 从数据库中批量导出图片

时间:2011-5-24来源:yang 作者: peng点击: 383次

procedure TFrmMain.btn1Click(Sender: TObject);
Var
      tempstream:TStringStream;
      tempjpeg:TJPEGImage;
      ecode,PathStr,sqlstr,str,str2:string;
      num :Integer;
begin
   PathStr := ExtractFilePath(Application.ExeName) + ‘img\‘;

   //if not qry1.Active then  qry1.Open;
   try
    with qry1 do
    begin
    sqlstr:= ‘select ecode,ename,ePicture from  emploees where  epicture is not null  ‘ ;
    if trim(cbb1.Text)=‘‘  then
      showMessage(‘请选择部门!‘)
    else
    begin
    str := Copy(trim(cbb1.Text),1,Pos(‘-‘,trim(cbb1.Text))-1);
    str2 :=‘ and  (DEpId like ‘‘‘+str+‘%‘‘   or DpCode like ‘‘‘+str+‘%‘‘  or GCode like ‘‘‘+str+‘%‘‘  or CTcode like ‘‘‘+str+‘%‘‘  ) ‘;
    sqlstr := sqlstr+ str2;
    end;
    close;
    sql.clear;
    sql.Add(sqlstr);
    Open;
    end;
   except
    on e:Exception do
     begin
     ShowMessage(‘错误!‘+e.Message);
     Exit;
     end;

   end;

   num := qry1.RecordCount;
   qry1.First;
  pb1.Max := num;

 while not  qry1.Eof do
  begin
   if qry1.FieldByName(‘Epicture‘).Value<>‘‘ then
    begin
     try
          qry1.Edit;
          ecode := qry1.FieldByName(‘ecode‘).Value+‘-‘+qry1.FieldByName(‘ename‘).Value ;
         stat1.Panels[1].Text := ecode;
          tempstream:=TStringStream.Create(‘‘);
          tempjpeg:=TJPEGImage.Create;

          TBlobField(qry1.FieldByName(‘Epicture‘)).SaveToStream(tempstream);
          tempstream.Position:=0;

          tempjpeg.LoadFromStream(tempstream);
          img1.Picture.Bitmap.Assign(tempjpeg);

          img1.Picture.Graphic.SaveToFile(PathStr + ecode +‘.jpg‘);
       pb1.Position := pb1.Position + 1  ;

      finally
          tempstream.Free;
          tempjpeg.Free;
      end;
    end;

    qry1.Next;

  end;

   ShowMessage(‘导出完毕 :)‘);
   pb1.Position :=0;
   stat1.Panels[1].Text := ‘共‘ + inttostr(num) +‘张照片。‘

  end;

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Delphi中QuotedStr介绍及使用
Delphi中Copy的使用
DELPHI生成随机字符串
Delphi 关闭指定窗口标题的窗口
Delphi PChar与String互转
安全文本操作 类
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服