怎么把图片保存到数据表中?

解决方案 »

  1.   

    procedure TForm1.BitBtn2Click(Sender: TObject);  //保存图片
    var
      ms  :TMemoryStream;
      ext :string;
    begin
      if edtDrNameSp.Text= '' then exit;
      if edtDrNameTy.Text= '' then exit;
      if edtDrNameE.Text= '' then exit;
      if not ImageEn1.IsEmpty then
        begin
          ext:= Extractfileext(OpenPictureDialog1.FileName);
          ms := TMemoryStream.Create;
          try
          try
              if Uppercase(ext)= '.BMP' then
                begin
                  ImageEn1.SaveToStreamBMP(ms);
                end
              else if  (Uppercase(ext)= '.JPG') or (Uppercase(ext)= '.JPEG') then
                begin
                  ImageEn1.SaveToStreamJpeg(ms);
                end;
            adoQryTmp.Active:= false;
            adoQryTmp.SQL.Clear;
            adoQryTmp.SQL.Add('select * from drimages');
            adoQryTmp.Active:= true;
            ms.Position:= 0;
            adoQryTmp.Append;
            adoQryTmp.FieldByName('drNameSp').Value:= Trim(edtDrNameSp.Text);
            adoQryTmp.FieldByName('drNameSpPy').Value:= Trim(edtDrNameSpPy.Text);
            adoQryTmp.FieldByName('drNameTy').Value:= Trim(edtDrNameTy.Text);
            adoQryTmp.FieldByName('drNameTyPy').Value:= Trim(edtDrNameTyPy.Text);
            adoQryTmp.FieldByName('drNameE').Value:= Trim(edtDrNameE.Text);
            TBlobField(adoQryTmp.FieldByName('drimage')).LoadFromStream(ms);
            adoQryTmp.FieldByName('indate').Value:=now;
            adoQryTmp.FieldByName('memo').Value:= RedtMemo.Text;
              if Uppercase(ext)= '.BMP' then
                begin
                  adoQryTmp.FieldByName('isbmp').Value:= 1;
                end
              else if  (Uppercase(ext)= '.JPG') or (Uppercase(ext)= '.JPEG') then
                begin
                  adoQryTmp.FieldByName('isbmp').Value:= 0;
                end;
            adoQryTmp.Post;
            Clearedt;
          finally
            ms.Free;
          end;
          application.MessageBox('图片保存成功!','提示',mb_OK);
          adoQry.Active:= false;
          adoQry.Active:= true;
          except
          on e:exception do
            begin
              application.MessageBox('图片保存失败!','警告!',mb_OK);
            end;
          end;
        end;
    end;
      

  2.   

    procedure TForm1.DBGrid1CellClick(Column: TColumn);   //调出图片
    var
      ms :TMemoryStream;
    begin
      ImageEn1.SetFocus;
      if adoQry.Active = false then exit;
      if AdoQry.RecordCount <1 then exit;
      idd:= adoQry.fieldbyname('id').AsInteger;
      RedtMemo.Text:= adoQry.fieldbyname('memo').Value;
      ms := TadoBlobStream.Create(TBlobField(adoQry.FieldByName('drimage')),bmread);
      try
        ms.Position:= 0;
        ImageEn1.Clear;
        if adoQry.FieldByName('isbmp').AsInteger = 1 then
          begin
            ImageEn1.LoadFromStreamBMP(ms);
          end
        else
          begin
            ImageEn1.LoadFromStreamJpeg(ms);
          end;
      finally
        ms.Free;
      end;
    end;
      

  3.   

    楼上的,能否写的完整点,我也急着要这方面的资料.ImageEn1.SaveToStreamBMP(ms); 像这里的,ImageEn1是什么控件,我比较菜,不知哪个控件里有SaveToStreamBMP方法.你能否搞一个完整的实例发我    QQ :85055315  感激不尽.