360教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

用delphi大局部导入某子目录下所有JPG图片文件到数据库

时间:2022-9-15作者:未知来源:360教程人气:

//保存图片到数据库
function imagesavetosql(dataset:TQuery;filename:String):boolean;
var
  imagejpg:TJPEGImage; //jpg图片
  MyStm:TMemoryStream;
begin
  result:=false;
  MyStm:=TMemoryStream.Create;
  imagejpg:=Tjpegimage.Create;
  if filename<>'' then
  begin
    imagejpg.LoadFromFile(filename);
    imagejpg.SaveToStream(MyStm);
    MyStm.Position:=0;
    TBlobField(dataset.FieldByName('pict')).LoadFromStream(MyStm); //不可与DMImage之类控件,因为其只支持BMP
    result:=true;
  end;
  MyStm.Free;
  imagejpg.free;
end;
//界面上添加TDirectoryListBox,TGauge控件
procedure Tfrmpict.BitBtn2Click(Sender: TObject);
var
  dirlist:TStringList;
  i:Integer;
begin
  inherited;
  if chk_road.Checked  then
  begin
    dirlist:=TStringList.Create ;
    dirlist.Clear;
    try
      GetAllFileName(DirectoryListBox1.Directory,dirlist);
      if dirlist.Count>0 then
      begin
      Gauge1.MinValue :=0;
      Gauge1.MaxValue:= dirlist.Count-1;
      for i:=0 to dirlist.Count-1 do
      begin
       with dm.qry_pict do
       begin
         Insert;
         Fields[0].AsString:=copy(dirlist.Strings[i],1,pos('.',dirlist.Strings[i])-1);
         if imagesavetosql(dm.qry_pict,dirlist.Strings[i] )=false then
         begin
         ShowMessage('导入'+dirlist.Strings[i]+'.jpg图片时出错');
         Abort;
         end;
         Post;
       end;  //with
       Gauge1.AddProgress(1);
      end;  //for
      end  //if
      else
      ShowMessage('该目录下不存在JPG类型图片');
      
    finally
      dirlist.Free;
    end;

  end
  else
     ShowMessage('请执行路径选取操作');

  //Close;
end;

关键词:用delphi大局部导入某子目录下所有JPG图片文件到数据库




Copyright © 2012-2018 360教程(http://www.360sd.cn) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版