如何在DELPHI 中存取ACCESS中的图象???????请各位兄弟姐妹用例子说明一下!谢谢!

解决方案 »

  1.   

    procedure TDriverInfoForm.BitBtn1Click(Sender: TObject);
    var
            ImageField:TField;
            Picture:TPicture;
            
    begin
      
    if OpenPicDlg.Execute then
    Begin
            with DataSource.DataSet do
            try
              Query.Edit;
              ImageField := FindField('Pic');
              if ImageField <> nil then
              begin
                Picture := TPicture.Create;
                try
                  Query.Edit;
                  Picture.LoadFromFile(OpenPicDlg.FileName);
                  if Picture.Graphic is TBitmap then
                    ImageField.Assign(Picture)
                  else
                  SaveGraphicToBlobField(Picture.Graphic, ImageField);
                finally
                  Picture.Free;
                  end;
              end;
              
            except
            end;
    End;
    end;procedure SaveGraphicToBlobField(AGraphic: TGraphic; AField: TField);
    var
      BlobStream: TStream;
    begin
      if AField is TBlobField then
        with AField as TBlobField do
        begin
          {$IFNDEF DELPHI3}
          BlobStream := TBlobStream.Create(AField as TBlobField, bmWrite);
          {$ELSE}
          BlobStream := DataSet.CreateBlobStream(AField, bmWrite);
          {$ENDIF}
          try
            AGraphic.SaveToStream(BlobStream);
          finally
            BlobStream.Free;
          end;
        end;
    end;显示的话直接用DBImage就可以了
      

  2.   

    处理数据直接使用DBImage处理就行了。
      

  3.   

    DBimage 好象不支持吧!看了您的建议后我试了,出现错误提示为"Bitmap image
    is not valid"可以通过别的方法来实现嘛?
      

  4.   

    保存为文件的话这样就可以了。
    DBImage1.Picture.SaveToFile('c:\Text.bmp');
    你是要保存为文件还是什么别的应用??
      

  5.   

    谢谢您!从ACCESS库中提取BMP图象成功了。但是如果库中存的是JEG或JPEG图象就出现错误了,错误信息为:"Bitmap image is not valid“。说明:我用的是DBimage+ADOquery 
      

  6.   

    在你的处理单元里面加上use jpeg; 试一试。