Access中保存图片

 将JPG格式图片保存到ACCESS数据表中

 

var
  Ind,i:Integer;
  FName:string;
  AJPeg:TJPEGImage;
  temp:TBitmap;
begin
  if opd1.Execute then
  begin
    btnAdd.Enabled:=False;
    Ind:=Opd1.Files.Count;
    for i:=0 to Ind-1 do
    begin
      FName:=opd1.Files.Strings[i];
      Application.ProcessMessages;
      tbl1.Append;
      tblPictureName.AsString:=FName;
      if UpperCase(Copy(FName,Length(Fname)-3,4))=’.JPG’ then
      begin
        AJpeg:=TJPEGImage.Create;
        AJpeg.LoadFromFile(FName);
        Temp:=TBitmap.Create;
       Image1.Height:=Ajpeg.Height;
        Image1.Width:=Ajpeg.Width;
        Image1.Picture:=nil;
        Image1.Canvas.Draw(0,0,Ajpeg);
        DBImage1.Picture:=Image1.Picture;
        AJpeg.Free;
      end
      else
        tblPicture.LoadFromFile(FName);
      tbl1.Post;
    end;
  end;
说明:
tbl1:TADOQuery;
opd1:TOpenPictureDialog;

tblPicture是tbl1的字段,OLE型。
uses
  JPEG;
************************************************************
 人家是用access,肯定用ado的。  
  uses   Jpeg  
   
  procedure   SaveBitmapToDb(const   FileName:   string);  
  var  
      Bitmap:   TBitmap;  
      JpegImage:   TJpegImage;  
      MS:   TMemoryStream;  
  begin  
      Bitmap   :=   TBitmap.Create;  
      JpegImage   :=   TJpegImage.Create;  
      MS   :=   TMemoryStream.Create;  
      try  
          Bitmap.LoadFromFile(FileName);  
          JpegImage.Assign(Bitmap);  
          JpegImage.SaveToStream(MS);  
          AdoTable1.Append;  
          TBlobField(AdoTable1.FieldByName('Picture')).LoadFromStream(MS);  
          AdoTable1.Post;  
      finally  
          Bitmap.Free;  
          JpegImage.Free;  
          MS.Free;  
      end;  
  end;  

判断照片字段是否为空用if dmdata.ADOQUserInfo.FieldByName('照片').IsNull,清空image中的图像用image.picture:=NIL值为NIL.

你可能感兴趣的:(image,String,Integer,Access,照片)